home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 576-600 / disk_587 / conlib / conlib200.asm < prev    next >
Assembly Source File  |  1992-05-06  |  63KB  |  2,917 lines

  1. ;==================================================================
  2. ;===
  3. ;===    Name:    Console Library
  4. ;===
  5. ;===    Author:    Bjørn Reese
  6. ;===
  7. ;===    This source is Public Domain.
  8. ;===
  9. ;==================================================================
  10.  
  11. ;--- Comment ------------------------------------------------------
  12. ;
  13. ; TAB = 8    ;    POINTER = ^
  14. ;
  15. ; Source is rather messy and it could have been better documented
  16. ; but I'm really to lazy.
  17. ;
  18. ; The label convention used in this source is descriped in the
  19. ; article "PROGDOC.ART". If you're not in possesion of it just
  20. ; ignore the leading lower case letters of the labels.
  21. ;
  22. ; Keep the code PC-relative and ReEntrant!
  23. ; ( i.e. local variables on stack [ with LINK ] )
  24. ;
  25. ;------------------------------------------------------------------
  26.  
  27. ;--- System -------------------------------------------------------
  28.  
  29. DEBUG    = 1    ;0 = No Debugging
  30.  
  31.     INCDIR    INCLUDE:
  32.  
  33. vir    REG    d2-d7/a2-a6    ;Very Important Registers
  34. all    REG    d0-d7/a0-a6
  35.  
  36. TRUE    = 0
  37. FALSE    = -1
  38.  
  39. ;--- Include ------------------------------------------------------
  40.  
  41.     INCLUDE    exec/resident.i
  42.     INCLUDE    exec/nodes.i
  43.     INCLUDE    exec/lists.i
  44.     INCLUDE    exec/initializers.i
  45.     INCLUDE    exec/libraries.i
  46.     INCLUDE    exec/exec_lib.i
  47.     INCLUDE    exec/ports.i
  48.     INCLUDE    exec/memory.i
  49.     INCLUDE    graphics/text.i
  50.     INCLUDE    libraries/dos_lib.i
  51.     INCLUDE    devices/inputevent.i
  52.     INCLUDE    devices/conunit.i
  53.     INCLUDE    intuition/intuition_lib.i
  54.     INCLUDE    intuition/intuition.i
  55.     INCLUDE    work/con_lib.i        ;or whereever you got them.
  56.     INCLUDE    work/con.i
  57.  
  58. _LVORawKeyConvert    = -48
  59. ThisTask        = 276
  60. CSI            = 155
  61.  
  62. IEQUALIFIER_SHIFT    = IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT
  63. IEQUALIFIER_COMMAND    = IEQUALIFIER_LCOMMAND!IEQUALIFIER_RCOMMAND
  64. IEQUALIFIER_ALT        = IEQUALIFIER_LALT!IEQUALIFIER_RALT
  65.  
  66. ;--- Macro --------------------------------------------------------
  67.  
  68. CALL:    MACRO    ;Call System Function    name
  69.     jsr    _LVO\1(a6)
  70.     ENDM
  71.  
  72. PUSH:    MACRO    ;Push to stack        reg-list
  73.     movem.l    \1,-(sp)
  74.     ENDM
  75.  
  76. PULL:    MACRO    ;Pull from stack    reg-list
  77.     movem.l    (sp)+,\1
  78.     ENDM
  79.  
  80. DLINK:    MACRO    ;Dynamic Link        An,<ea>
  81.     move.l    \1,-(sp)
  82.     move.l    sp,\1
  83.     suba.w    \2,sp
  84.     ENDM
  85.  
  86. ABSW:    MACRO    ;Absolute Value Word    <ea>
  87.     addq.w    #1,\1
  88.     and.w    #-2,\1
  89.     ENDM
  90.  
  91. RETURN:    MACRO    ;Return            { Error [-127..128] }
  92.     IF    NARG=0
  93.     moveq    #0,d0
  94.     ELSE
  95.     moveq    #\1,d0
  96.     ENDC
  97.     rts
  98.     ENDM
  99.  
  100.  
  101. ;--- Constant -----------------------------------------------------
  102.  
  103. cVersion    = 2
  104. cRevision    = 0
  105. cPriority    = 0
  106.  
  107. cAcceptBufferSize= 30
  108.  
  109.  
  110. ;==================================================================
  111. ;==================================================================
  112. ;===                                ===
  113. ;===            CODE  AREA                ===
  114. ;===                                ===
  115. ;==================================================================
  116. ;==================================================================
  117.  
  118.     SECTION    ConLib,CODE
  119.  
  120.     IFNE    DEBUG
  121. start:    jmp    DebugCode
  122.     ENDC
  123.  
  124. ;------------------------------------------------------------------
  125. ;    @IllegalStart
  126. ;------------------------------------------------------------------
  127. ;
  128. ; If Library is executed it will perform this procedure, which
  129. ; displays an error message on Standard Output Stream.
  130. ;
  131. ;------------------------------------------------------------------
  132.  
  133. IllegalStart:
  134.     move.l    $0004.w,a6        ;If Library is executed
  135.     move.l    378(a6),a0
  136.     lea    sDosName(pc),a1
  137.     CALL    FindName        ;Find Dos Library
  138.     move.l    d0,a6
  139.     CALL    Output            ;Find Standard Output Stream
  140.     move.l    d0,d1
  141.     beq.s    .End
  142.     pea    sDosText(pc)
  143.     move.l    (sp)+,d2
  144.     move.l    #sDosTextEnd-sDosText,d3
  145.     CALL    Write            ;Write Error Text
  146. .End    RETURN    30            ;Report an error
  147.  
  148. ;==================================================================
  149. ;===
  150. ;===    Standard Resident Library Structure
  151. ;===
  152. ;==================================================================
  153.  
  154.     CNOP    0,4
  155. RomTag:
  156.     dc.w    RTC_MATCHWORD
  157.     dc.l    RomTag
  158.     dc.l    EndLib
  159.     dc.b    RTF_AUTOINIT
  160.     dc.b    cVersion
  161.     dc.b    NT_LIBRARY
  162.     dc.b    cPriority
  163.     dc.l    sLibName
  164.     dc.l    sLibID
  165.     dc.l    Init
  166. Init:
  167.     dc.l    con_SIZEOF    ;Positive BaseSize
  168.     dc.l    LibFuncTable
  169.     dc.l    LibDataTable
  170.     dc.l    LibInit
  171.  
  172.  
  173. ;------------------------------------------------------------------
  174. LibFuncTable:
  175.     dc.l    LibOpen        ;Open Library
  176.     dc.l    LibClose    ;Close Library
  177.     dc.l    LibExpunge    ;Remove Library
  178.     dc.l    LibExtFunc    ;free for expansion
  179.  
  180.     dc.l    OpenCon
  181.     dc.l    CloseCon
  182.     dc.l    DoFormat
  183.     dc.l    UserNotes
  184.     dc.l    DefineChars
  185.     dc.l    DisplayRaw
  186.     dc.l    Display
  187.     dc.l    Accept
  188.     dc.l    AcceptString
  189.     dc.l    SetMsgHandler
  190.     dc.l    GetInfo
  191.     dc.l    SetGfx
  192.     dc.l    GotoXY
  193.     dc.l    Cursor
  194.     dc.l    Scroll
  195.     dc.l    Convert
  196.  
  197.     dc.l    -1
  198.  
  199. ;------------------------------------------------------------------
  200. LibDataTable:
  201.     INITBYTE    LH_TYPE,NT_LIBRARY
  202.     INITLONG    LN_NAME,sLibName
  203.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  204.     INITWORD    LIB_VERSION,cVersion
  205.     INITWORD    LIB_REVISION,cRevision
  206.     INITLONG    LIB_IDSTRING,sLibID
  207.     dc.l    0    
  208.  
  209. ;==================================================================
  210. ;===
  211. ;===    Private Library Functions
  212. ;===
  213. ;==================================================================
  214.  
  215. ;------------------------------------------------------------------
  216. ;    @LibInit
  217. ;------------------------------------------------------------------
  218. ;
  219. ; Initialize Library.
  220. ;
  221. ;------------------------------------------------------------------
  222. ; IN    d0.l    = ConBase
  223. ;    a0.l    = SegList [ from LoadSeg() ]
  224. ; OUT    d0.l    = ConBase
  225. ;------------------------------------------------------------------
  226.  
  227. LibInit:
  228.     PUSH    all
  229.  
  230.     move.l    d0,a4            ;--- SET UP LIB VALUES
  231.     move.l    a0,con_SegList(a4)
  232.     clr.l    con_IntBase(a4)
  233.     lea    pSysBase(pc),a1
  234.     move.l    $0004.w,(a1)
  235.     move.l    pSysBase(pc),a6
  236.  
  237.     moveq    #0,d0            ;--- OPEN INTUITION LIBRARY
  238.     lea    sIntName(pc),a1
  239.     CALL    OpenLibrary
  240.     move.l    d0,con_IntBase(a4)
  241.  
  242.     moveq    #0,d0            ;--- OPEN MATHFFP LIBRARY
  243.     lea    sMathName(pc),a1
  244.     CALL    OpenLibrary
  245.     move.l    d0,con_MathBase(a4)
  246.  
  247.     lea    dWriteReplyPort(pc),a1    ;--- MAKE REPLYPORT
  248.     CALL    AddPort
  249.  
  250.     PULL    all
  251.     rts
  252.  
  253. ;------------------------------------------------------------------
  254. ;    @LibOpen
  255. ;------------------------------------------------------------------
  256. ;
  257. ; Open Library.
  258. ;
  259. ;------------------------------------------------------------------
  260. ; IN    a6.l    = ConBase
  261. ; OUT    d0.l    = ConBase
  262. ;------------------------------------------------------------------
  263.  
  264. LibOpen:
  265.     addq.w    #1,LIB_OPENCNT(a6)
  266.     bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  267.     move.l    a6,d0
  268.     rts
  269.  
  270. ;------------------------------------------------------------------
  271. ;    @LibClose
  272. ;------------------------------------------------------------------
  273. ;
  274. ; Close Library.
  275. ;
  276. ; Expunge if (LIB_OPENCNT = 0) AND (LIBB_DELEXP IN LIB_FLAGS)
  277. ;
  278. ;------------------------------------------------------------------
  279. ; IN    a6.l    = ConBase
  280. ; OUT    -
  281. ;------------------------------------------------------------------
  282.  
  283. LibClose:
  284.     moveq    #0,d0
  285.     subq.w    #1,LIB_OPENCNT(a6)
  286.     bne.s    .Exit
  287.     btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  288.     beq.s    .Exit
  289.     bra.s    LibExpunge
  290. .Exit    rts
  291.  
  292.  
  293. ;------------------------------------------------------------------
  294. ;    @LibExpunge
  295. ;------------------------------------------------------------------
  296. ;
  297. ; Expunge Library.
  298. ;
  299. ; This procedure is called if Exec tries to gain some memory.
  300. ;
  301. ;------------------------------------------------------------------
  302. ; IN    a6    = ConBase
  303. ; OUT    d0.l    = NULL (Stay in memory)
  304. ;          ! SegList (UnLoadSeg me)
  305. ;------------------------------------------------------------------
  306.  
  307. LibExpunge:
  308.     PUSH    d1-d7/a0-a6
  309.     move.l    a6,a4
  310.     move.l    pSysBase(pc),a6
  311.     tst.w    LIB_OPENCNT(a4)
  312.     bne.s    .DontExpungeYet
  313.  
  314.     lea    dWriteReplyPort(pc),a1    ;--- REMOVE REPLYPORT
  315.     CALL    RemPort
  316.  
  317.     move.l    con_MathBase(a4),a1    ;--- CLOSE MATHFFP LIBRARY
  318.     CALL    CloseLibrary
  319.  
  320.     move.l    con_IntBase(a4),a1    ;--- CLOSE INTUITION LIBRARY
  321.     CALL    CloseLibrary
  322.  
  323.     move.l    con_SegList(a4),d2
  324.     move.l    a4,a1
  325.     CALL    Remove            ;--- REMOVE LIB NODE
  326.     moveq    #0,d0
  327.  
  328.     move.l    a4,a1            ;--- FREE LIB SPACE
  329.     move.w    LIB_NEGSIZE(a4),d0
  330.     suba.l    d0,a1            ;PTR = LIBBASE - LIB_NEGSIZE
  331.     add.w    LIB_POSSIZE(a4),d0    ;SIZE = LIB_NEGSIZE + LIB_POSSIZE
  332.     CALL    FreeMem
  333.     move.l    d2,d0
  334.     bra.s    .Exit
  335.  
  336. .DontExpungeYet
  337.     bset    #LIBB_DELEXP,LIB_FLAGS(a4)
  338.     moveq    #0,d0
  339.  
  340. .Exit    PULL    d1-d7/a0-a6
  341.     rts
  342.  
  343.  
  344. ;------------------------------------------------------------------
  345. ;    @LibExtFunc
  346. ;------------------------------------------------------------------
  347. ;
  348. ; Dummy.
  349. ;
  350. ;------------------------------------------------------------------
  351.  
  352. LibExtFunc:
  353.     moveq    #0,d0
  354.     rts
  355.  
  356.  
  357. ;==================================================================
  358. ;===
  359. ;===    Public Library Functions
  360. ;===
  361. ;==================================================================
  362.  
  363. ;------------------------------------------------------------------
  364. ;    @OpenCon
  365. ;------------------------------------------------------------------
  366. ;
  367. ; Open a Console Window.
  368. ;
  369. ; A Console Window is an Intuition Window with console.device
  370. ; attached.
  371. ;
  372. ;------------------------------------------------------------------
  373. ; IN    d0.w    = CursorMode
  374. ;    a0.l    = Window Struct
  375. ; OUT    d0.l    = ConHandle
  376. ;------------------------------------------------------------------
  377.  
  378. vpConBase    SET    -4
  379. vpMyWindow    SET    vpConBase-4
  380. vpConHandle    SET    vpMyWindow-4
  381. vwCursor    SET    vpConHandle-2
  382. vSizeOf        SET    vwCursor
  383.  
  384. OpenCon:
  385.     PUSH    vir
  386.     link    a4,#vSizeOf
  387.     move.l    a6,vpConBase(a4)
  388.     move.l    a0,vpMyWindow(a4)
  389.     move.w    d0,vwCursor(a4)
  390.  
  391.     move.l    #MEMF_CLEAR,d1        ;--- ALLOC MEMORY FOR ConHandle & WriteIO
  392.     move.l    #cnh_SIZEOF+IOSTD_SIZE,d0
  393.     move.l    pSysBase(pc),a6
  394.     CALL    AllocMem
  395.     move.l    d0,vpConHandle(a4)
  396.     beq.w    .Exit
  397.     move.l    d0,a3
  398.     add.l    #cnh_SIZEOF,d0
  399.     move.l    d0,cnh_WriteIO(a3)
  400.     move.w    #256,cnh_ExLength(a3)    ;default for ExLength
  401.     move.w    vwCursor(a4),cnh_CursorStatus(a3)
  402.  
  403.     move.l    vpMyWindow(a4),a0    ;--- OPEN WINDOW
  404.     move.l    nw_IDCMPFlags(a0),d0
  405.     and.l    #~VANILLAKEY,d0        ;VANILLAKEY not allowed
  406.     or.l    #RAWKEY,d0        ;...we need RAWKEY
  407.     move.l    d0,nw_IDCMPFlags(a0)
  408.     move.l    vpConBase(a4),a6
  409.     move.l    con_IntBase(a6),a6
  410.     CALL    OpenWindow
  411.     move.l    d0,cnh_Window(a3)
  412.     beq.w    .Error1
  413.     move.l    d0,a0
  414.     move.l    wd_UserPort(a0),cnh_UserPort(a3)
  415.  
  416.     move.l    cnh_WriteIO(a3),a1    ;--- OPEN CONSOLE DEVICE
  417.     move.l    cnh_Window(a3),IO_DATA(a1)
  418.     move.l    #nw_SIZE,IO_LENGTH(a1)
  419.     moveq    #0,d0
  420.     moveq    #0,d1
  421.     lea    sConDevName(pc),a0
  422.     move.l    pSysBase(pc),a6
  423.     CALL    OpenDevice
  424.     tst.l    d0
  425.     bne.s    .Error2
  426.     move.l    cnh_WriteIO(a3),a0
  427.     move.l    IO_DEVICE(a0),cnh_CDBase(a3)
  428.     move.l    IO_UNIT(a0),cnh_Unit(a3)
  429.  
  430.     move.l    cnh_UserPort(a3),a0    ;--- MAKE SIGNAL
  431.     move.b    MP_SIGBIT(a0),d0
  432.     moveq    #0,d1
  433.     bset    d0,d1
  434.     move.l    d1,cnh_Signal(a3)
  435.  
  436.     lea    cnh_EchoTable(a3),a1    ;--- MAKE ECHOTABLE
  437.     move.l    #DEFMODE_GET+DEFALFANUM,d0
  438.     bsr    DefineChars
  439.  
  440.     move.w    vwCursor(a4),d0
  441.     move.l    vpConHandle(a4),a0
  442.     bsr    Cursor
  443.  
  444.     move.w    #' 0',cnh_PadSpace(a3)        ;PadSpace & PadZero
  445.     move.w    #'..',cnh_PadGroup(a3)        ;PadGroup & PadString
  446.     move.w    #',E',cnh_DecimalPoint(a3)    ;DecimalPoint & FloatE
  447.  
  448.     move.l    vpConHandle(a4),d0
  449. .Exit    unlk    a4
  450.     PULL    vir
  451.     rts
  452.  
  453. .Error2    move.l    cnh_Window(a3),a0    ;--- CLOSE WINDOW
  454.     move.l    vpConBase(a4),a6
  455.     move.l    con_IntBase(a6),a6
  456.     CALL    CloseWindow
  457.  
  458. .Error1    move.l    vpConHandle(a4),a1    ;--- RELEASE ALL MEMORY
  459.     move.l    #cnh_SIZEOF+IOSTD_SIZE,d0
  460.     move.l    pSysBase(pc),a6
  461.     CALL    FreeMem
  462.     moveq    #0,d0
  463.     bra.s    .Exit
  464.  
  465. ;------------------------------------------------------------------
  466. ;    @CloseCon
  467. ;------------------------------------------------------------------
  468. ;
  469. ; Close a Console Window.
  470. ;
  471. ;------------------------------------------------------------------
  472. ; IN    a0.l    = ConHandle
  473. ; OUT    -
  474. ;------------------------------------------------------------------
  475.  
  476. vpConBase    SET    -4
  477. vpConHandle    SET    vpConBase-4
  478. vSizeOf        SET    vpConHandle
  479.  
  480. CloseCon:
  481.     PUSH    vir
  482.     link    a4,#vSizeOf
  483.     move.l    a6,vpConBase(a4)
  484.     move.l    a0,vpConHandle(a4)
  485.     beq.s    .Exit
  486.  
  487.     move.l    vpConHandle(a4),a3    ;--- CLOSE CONSOLE DEVICE
  488.     move.l    cnh_WriteIO(a3),a1
  489.     move.l    pSysBase(pc),a6
  490.     CALL    CloseDevice
  491.  
  492.     move.l    cnh_Window(a3),a0    ;--- CLOSE WINDOW
  493.     move.l    vpConBase(a4),a6
  494.     move.l    con_IntBase(a6),a6
  495.     CALL    CloseWindow
  496.  
  497.     move.l    vpConHandle(a4),a1    ;--- RELEASE ALL MEMORY
  498.     move.l    #cnh_SIZEOF+IOSTD_SIZE,d0
  499.     move.l    pSysBase(pc),a6
  500.     CALL    FreeMem
  501.  
  502. .Exit    unlk    a4
  503.     PULL    vir
  504.     rts
  505.  
  506. ;------------------------------------------------------------------
  507. ;    @UserNotes
  508. ;------------------------------------------------------------------
  509. ;
  510. ; Make a user note.
  511. ;
  512. ;------------------------------------------------------------------
  513. ; IN    d0.w    = Note Number
  514. ;    a0.l    = ConHandle
  515. ;    a1.l    = ^String [ NULL terminated ]
  516. ; OUT    -
  517. ;------------------------------------------------------------------
  518.  
  519. UserNotes:
  520.     lea    cnh_UserNotes(a0),a2
  521.     subq.w    #1,d0
  522.     add.w    d0,d0
  523.     add.w    d0,d0
  524.     and.w    #$000E,d0
  525.     move.l    a1,(a2,d0.w)
  526.     rts
  527.  
  528. ;------------------------------------------------------------------
  529. ;    @DoFormat
  530. ;------------------------------------------------------------------
  531. ;
  532. ; Format a text string. Works much like RawDoFmt() or sprintf().
  533. ;
  534. ; DoFormat supports:
  535. ;
  536. ;    \ arguments:
  537. ;
  538. ;        Standard:    n t \ f b r v
  539. ;        Non-Standard:    @ B I U C Z[ nnn    (* =chr(nnn)* )
  540. ;        User-Defined:    #n            (* n=[1..8] *)
  541. ;
  542. ;    % arguments:
  543. ;
  544. ;        d    = signed decimal
  545. ;        u    = unsigned decimal
  546. ;        x    = hex
  547. ;        c    = char
  548. ;        s    = string
  549. ;        o    = octal
  550. ;        b    = binary (NON-STD!!)
  551. ;      (*    e    = float (m.nnnnnnE±xx)    *)
  552. ;      (*    f    = float (mmm.nnnnnn)    *)    For later versions
  553. ;      (*    g    = float (%e or %f)    *)
  554. ;
  555. ; Format:    %-0xxx.yyy    +    [ s | c ]
  556. ; Format:    %-0xxx.yyyl    +    [ d | u | x | o | b ]
  557. ;
  558. ; [xxx|yyy] = * : get number from arg.list
  559. ;          ( size = word (bit 15-8 unused) )
  560. ;
  561. ; (* For later versions: Group specifier = .zzz *)
  562. ;
  563. ;
  564. ; Refer to documentation for further detail.
  565. ;
  566. ;------------------------------------------------------------------
  567. ; IN    d0.l    = MaxLen
  568. ;    a0.l    = ConHandle
  569. ;    a1.l    = String
  570. ;    a2.l    = List of Arguments
  571. ;    a3.l    = Text Buffer
  572. ; OUT    d0.l    = Formatted String
  573. ;------------------------------------------------------------------
  574.  
  575. dof_MINUS    = 1
  576. dof_ZERO    = 2
  577. dof_POINT    = 3
  578. dof_GROUP    = 4
  579. dof_LONG    = 5
  580. dof_NEG        = 6    ;Set if decimal is < 0
  581.  
  582. vpDataStream    SET    -4
  583. vpLastPosition    SET    vpDataStream-4
  584. vlMaxLen    SET    vpLastPosition-4
  585. vlPosition    SET    vlMaxLen-4
  586. vwFieldSize    SET    vlPosition-2
  587. vwLenSize    SET    vwFieldSize-2
  588. vwGroupSize    SET    vwLenSize-2
  589. vsSmallBuffer    SET    vwGroupSize-64
  590. vwSuccess    SET    vsSmallBuffer-2
  591. vSizeOf        SET    vwSuccess
  592.  
  593. DoFormat:
  594.     movem.l    d1-d7/a0-a3/a5,-(sp)
  595.     link    a4,#vSizeOf
  596.     move.l    d0,vlMaxLen(a4)
  597.     clr.l    vlPosition(a4)
  598.     move.l    a1,vpDataStream(a4)
  599.     bra.s    .Next
  600. .Normal    bsr.s    PutCharFunc
  601. .Next    clr.w    vwSuccess(a4)
  602.     move.b    (a1)+,d0
  603.     beq.s    .Exit
  604.     cmp.b    #'%',d0
  605.     bne.s    .NotPct
  606.     move.l    a1,vpLastPosition(a4)
  607.     bsr    DoProcent
  608.     tst.w    vwSuccess(a4)
  609.     beq.s    .Next
  610.     move.b    #'%',d0
  611.     bsr.s    PutCharFunc
  612.     move.l    vpLastPosition(a4),a1
  613.     bra.s    .Next
  614. .NotPct    cmp.b    #'\',d0
  615.     bne.s    .Normal
  616.     move.l    a1,vpLastPosition(a4)
  617.     bsr    DoBackSlash
  618.     tst.w    vwSuccess(a4)
  619.     bpl.s    .Next
  620.     move.b    #'\',d0
  621.     bsr.s    PutCharFunc
  622.     move.l    vpLastPosition(a4),a1
  623.     bra.s    .Next
  624. .Exit    bsr.s    PutCharFunc        ;Terminating NULL
  625.     move.l    a3,d0
  626.     unlk    a4
  627.     movem.l    (sp)+,d1-d7/a0-a3/a5
  628.     rts
  629.  
  630. ;------------------------------------------------------------------
  631. PutCharFunc:
  632.     move.l    vlPosition(a4),d1
  633.     cmp.l    vlMaxLen(a4),d1
  634.     bge.s    .001
  635.     addq.l    #1,vlPosition(a4)
  636. .001    move.b    d0,(a3,d1.l)
  637.     rts
  638.  
  639. ;------------------------------------------------------------------
  640. ;OUT    vwSuccess.w    = Success  (( -1 = Error ))
  641.  
  642. DoProcent:
  643.     moveq    #0,d3
  644.     move.b    (a1)+,d0
  645.     cmp.b    #'%',d0
  646.     beq    PutCharFunc
  647.     clr.w    vwFieldSize(a4)
  648.     clr.w    vwLenSize(a4)
  649.     clr.w    vwGroupSize(a4)
  650.     cmp.b    #'-',d0        ;left-justify?
  651.     bne.s    .001
  652.     bset    #dof_MINUS,d3
  653.     move.b    (a1)+,d0
  654. .001    cmp.b    #'0',d0        ;leading zero's?
  655.     bne.s    .002
  656.     bset    #dof_ZERO,d3
  657.     move.b    (a1)+,d0
  658. .002    bsr    GetNumber    ;field width?
  659.     tst.w    d1
  660.     bne.s    .005
  661.     move.w    d0,vwFieldSize(a4)
  662.     move.b    (a1)+,d0
  663. .005    cmp.b    #'.',d0        ;max len specifier?
  664.     bne.s    .003
  665.     bset    #dof_POINT,d3
  666.     move.b    (a1)+,d0
  667.     bsr    GetNumber    ;max len?
  668.     tst.w    d1
  669.     bne.s    .006
  670.     move.w    d0,vwLenSize(a4)
  671.     move.b    (a1)+,d0
  672. .006
  673. ;    cmp.b    #'.',d0        ;group specifier?
  674. ;    bne.s    .003
  675. ;    bset    #dof_GROUP,d3
  676. ;    move.b    (a1)+,d0
  677. ;    bsr    GetNumber    ;group?
  678. ;    tst.w    d1
  679. ;    bne.s    .003
  680. ;    move.w    d0,vwGroupSize(a4)
  681. ;    move.b    (a1)+,d0
  682.  
  683. .003    cmp.b    #'l',d0        ;long?
  684.     bne.s    .004
  685.     bset    #dof_LONG,d3
  686.     move.b    (a1)+,d0
  687.  
  688. .004    cmp.b    #'s',d0
  689.     beq.w    DopeString
  690.     cmp.b    #'d',d0
  691.     beq.w    DopeDecimal
  692.     cmp.b    #'x',d0
  693.     beq.w    DopeHex
  694.     cmp.b    #'u',d0
  695.     beq.w    DopeUnsigned
  696.     cmp.b    #'b',d0
  697.     beq.w    DopeBinary
  698.     cmp.b    #'c',d0
  699.     beq.w    DopeChar
  700.     cmp.b    #'o',d0
  701.     beq.w    DopeOctal
  702.  
  703. ;    cmp.b    #'e',d0
  704. ;    beq.s    DopeEFloat
  705. ;    cmp.b    #'f',d0
  706. ;    beq.s    DopeFFloat
  707. ;    cmp.b    #'g',d0
  708. ;    beq.s    DopeGFloat
  709.  
  710. DopeError:
  711.     move.w    #FALSE,vwSuccess(a4)
  712.     rts
  713.  
  714. ;------------------------------------------------------------------
  715. DopeString:
  716.     btst    #dof_LONG,d3
  717.     bne.w    DopeError
  718.     bclr    #dof_GROUP,d3
  719.     move.l    (a2)+,a5
  720.     move.l    a5,d7
  721.     moveq    #-1,d0            ;Calc TextLen
  722. .Loop    tst.b    (a5)+
  723.     dbeq    d0,.Loop
  724.     neg.w    d0
  725.     subq.w    #1,d0
  726.     move.l    d7,a5
  727.  
  728. ;...and fall down through...
  729.  
  730. ;------------------------------------------------------------------
  731. ;IN    d0.w    = Length of StringPart
  732. ;    a5.l    = ^StringPart to insert
  733.  
  734. StringParty:
  735.     move.w    vwFieldSize(a4),d7    ;Pad Length
  736.     move.w    vwLenSize(a4),d6    ;Put Length
  737.     beq.s    .001
  738.     cmp.w    d6,d0
  739.     bhi.s    .002
  740. .001    move.w    d0,d6
  741. .002    sub.w    d6,d7
  742.     bpl.s    .003
  743.     moveq    #0,d7
  744. .003    btst    #dof_MINUS,d3
  745.     bne.s    .202
  746.  
  747. ;--- Pre Pad
  748.     move.b    cnh_PadSpace(a0),d0    ;DoPadding
  749.     btst    #dof_ZERO,d3
  750.     beq.s    .101
  751.     move.b    cnh_PadString(a0),d0
  752.     bra.s    .101
  753. .PreLoop
  754.     bsr    PutCharFunc
  755. .101    dbra    d7,.PreLoop
  756.     bra.s    .102            ;DoPutString
  757. .PreSLoop
  758.     move.b    (a5)+,d0
  759.     beq.s    .103
  760.     bsr    PutCharFunc
  761. .102    dbra    d6,.PreSLoop
  762. .103    rts
  763.  
  764. ;--- Post Pad
  765. .PostLoop
  766.     move.b    (a5)+,d0        ;DoPutString
  767.     beq.s    .203
  768.     bsr    PutCharFunc
  769. .202    dbra    d6,.PostLoop
  770. .203    move.b    cnh_PadSpace(a0),d0    ;DoPadding
  771.     btst    #dof_ZERO,d3
  772.     beq.s    .201
  773.     move.b    cnh_PadString(a0),d0
  774.     bra.s    .201
  775. .PostSLoop
  776.     bsr    PutCharFunc
  777. .201    dbra    d7,.PostSLoop
  778.     rts
  779.  
  780. ;------------------------------------------------------------------
  781. DopeChar:
  782.     btst    #dof_LONG,d3
  783.     bne.w    DopeError
  784.     bclr    #dof_GROUP,d3
  785.     move.w    (a2)+,-(sp)
  786.     move.l    sp,a5
  787.     addq.l    #1,a5
  788.     moveq    #1,d0
  789.     bsr    StringParty
  790.     addq.l    #2,sp
  791.     rts
  792.  
  793. ;------------------------------------------------------------------
  794. DopeDecimal:
  795.     move.l    a0,-(sp)
  796.     lea    vsSmallBuffer(a4),a5
  797.     move.l    a5,d6
  798.  
  799.     btst    #dof_LONG,d3
  800.     bne.s    .Long
  801.     move.w    (a2)+,d0
  802.     ext.l    d0
  803.     beq.s    .Last
  804.     bra.s    .001
  805. .Long    move.l    (a2)+,d0
  806.     beq.s    .Last
  807. .001    bmi.s    .Neg
  808.     neg.l    d0
  809.     bra.s    .002
  810. .Neg    move.b    #'-',(a5)+
  811. .002    lea    alDecArray(pc),a0
  812.     moveq    #0,d1
  813. .OLoop    move.l    (a0)+,d2
  814.     beq.s    .Last
  815.     moveq    #-1,d5
  816. .Loop    add.l    d2,d0
  817.     dbgt    d5,.Loop
  818.     sub.l    d2,d0
  819.     addq.w    #1,d5
  820.     bne.s    .003
  821.     tst.w    d1
  822.     beq.s    .OLoop
  823. .003    moveq    #-1,d1
  824.     neg.b    d5
  825.     add.b    #'0',d5
  826.     move.b    d5,(a5)+
  827.     bra.s    .OLoop
  828. .Last    neg.b    d0
  829.     add.b    #'0',d0
  830.     move.b    d0,(a5)+
  831.     clr.b    (a5)
  832.     sub.l    a5,d6
  833.     neg.w    d6
  834.     move.w    d6,d0
  835.  
  836.     move.l    (sp)+,a0
  837.     lea    vsSmallBuffer(a4),a5
  838.     bra    PartyDudes
  839.  
  840.  
  841. ;------------------------------------------------------------------
  842. DopeUnsigned:
  843.     move.l    a0,-(sp)
  844.     lea    vsSmallBuffer(a4),a5
  845.     move.l    a5,d6
  846.     moveq    #0,d7
  847.  
  848.     btst    #dof_LONG,d3
  849.     bne.s    .Long
  850.     moveq    #0,d0
  851.     move.w    (a2)+,d0
  852.     beq.s    .Last
  853.     bra.s    .001
  854. .Long    move.l    (a2)+,d0
  855.     beq.s    .Last
  856.     bpl.s    .001
  857.     bclr    #31,d0
  858.     moveq    #-1,d7
  859.  
  860. .001    neg.l    d0
  861.     lea    alDecArray(pc),a0
  862.     moveq    #0,d1
  863. .OLoop    move.l    (a0)+,d2
  864.     beq.s    .Last
  865.     moveq    #-1,d5
  866. .Loop    add.l    d2,d0
  867.     dbgt    d5,.Loop
  868.     sub.l    d2,d0
  869.     addq.w    #1,d5
  870. ;    bne.s    .003
  871. ;    tst.w    d1
  872. ;    beq.s    .OLoop
  873. .003    moveq    #-1,d1
  874.     neg.b    d5
  875.     add.b    #'0',d5
  876.     move.b    d5,(a5)+
  877.     bra.s    .OLoop
  878. .Last    neg.b    d0
  879.     add.b    #'0',d0
  880.     move.b    d0,(a5)+
  881.     clr.b    (a5)
  882.     sub.l    a5,d6
  883.     neg.w    d6
  884.     move.w    d6,d0
  885.  
  886.     tst.w    d7
  887.     beq.s    .004
  888.     lea    abBlackAdder+10(pc),a0    ;Bungled work!
  889.     moveq    #0,d7
  890.     move.w    d6,d5
  891.     subq.w    #1,d5
  892.  
  893. .ALoop    move.b    -(a0),d1
  894.     move.b    -(a5),d2
  895.     add.b    d2,d1
  896.     sub.b    d7,d1
  897.     cmp.b    #'9',d1
  898.     sgt    d7
  899.     ble.s    .100
  900.     sub.b    #10,d1
  901. .100    move.b    d1,(a5)
  902.     dbra    d5,.ALoop
  903.  
  904. .004    move.l    (sp)+,a0
  905.     lea    vsSmallBuffer(a4),a5
  906.     moveq    #9-1,d5
  907. .4Loop    cmp.b    #'0',(a5)        ;Skip leading zeroes
  908.     bne.s    .4End
  909.     addq.l    #1,a5
  910.     dbra    d5,.4Loop
  911. .4End    bra    PartyDudes
  912.  
  913.  
  914. abBlackAdder:    dc.b    $02,$01,$04,$07,$04,$08,$03,$06,$04,$08
  915.     EVEN
  916.  
  917. ;------------------------------------------------------------------
  918. DopeHex:
  919.     lea    vsSmallBuffer(a4),a5
  920.     btst    #dof_LONG,d3
  921.     bne.s    .Long
  922.     moveq    #4-1,d2
  923.     move.w    (a2)+,d0
  924.     beq.s    .Zero
  925.     swap    d0
  926.     bra.s    .ZLoop
  927. .Long    moveq    #8-1,d2
  928.     move.l    (a2)+,d0
  929.     beq.s    .Zero
  930.  
  931. .ZLoop    rol.l    #4,d0
  932.     move.b    d0,d1
  933.     and.w    #$000f,d1
  934.     bne.s    .001
  935.     dbra    d2,.ZLoop
  936. .001    move.w    d2,d5
  937.     bra.s    .Entry
  938.  
  939. .NoZer    move.w    d2,d5
  940. .Loop    rol.l    #4,d0
  941.     move.b    d0,d1
  942.     and.w    #$000f,d1
  943. .Entry    move.b    sDopeHexString(pc,d1.w),(a5)+
  944.     dbra    d2,.Loop
  945.     lea    vsSmallBuffer(a4),a5
  946.     move.w    d5,d0
  947.     addq.w    #1,d0
  948.     bsr    PartyDudes
  949.     rts
  950.  
  951. .Zero    moveq    #0,d1
  952.     move.w    d1,d2
  953.     move.w    d2,d5
  954.     bra.s    .Entry
  955.  
  956. sDopeHexString:
  957.     dc.b    '0123456789ABCDEF'
  958.     EVEN
  959.  
  960. ;------------------------------------------------------------------
  961. DopeOctal:
  962.     lea    vsSmallBuffer(a4),a5
  963.     btst    #dof_LONG,d3
  964.     bne.s    .Long
  965.     moveq    #6-1,d2
  966.     move.w    (a2)+,d0
  967.     beq.s    .Zero
  968.     swap    d0
  969.     rol.l    #1,d0
  970.     move.b    d0,d1
  971.     and.w    #$0001,d1
  972.     bne.s    .001
  973.     subq.w    #1,d2
  974.     bra.s    .ZLoop
  975. .Long    moveq    #11-1,d2
  976.     move.l    (a2)+,d0
  977.     beq.s    .Zero
  978.     rol.l    #2,d0
  979.     move.b    d0,d1
  980.     and.w    #$0003,d1
  981.     bne.s    .001
  982.     subq.w    #1,d2
  983.  
  984. .ZLoop    rol.l    #3,d0
  985.     move.b    d0,d1
  986.     and.w    #$0007,d1
  987.     bne.s    .001
  988.     dbra    d2,.ZLoop
  989. .001    move.w    d2,d5
  990.     bra.s    .Entry
  991.  
  992. .NoZer    move.w    d2,d5
  993. .Loop    rol.l    #3,d0
  994.     move.b    d0,d1
  995.     and.w    #$0007,d1
  996. .Entry    move.b    sDopeHexString(pc,d1.w),(a5)+
  997.     dbra    d2,.Loop
  998.     lea    vsSmallBuffer(a4),a5
  999.     move.w    d5,d0
  1000.     addq.w    #1,d0
  1001.     bsr    PartyDudes
  1002.     rts
  1003.  
  1004. .Zero    moveq    #0,d1
  1005.     move.w    d1,d2
  1006.     move.w    d2,d5
  1007.     bra.s    .Entry
  1008.  
  1009. ;------------------------------------------------------------------
  1010. DopeBinary:
  1011.     lea    vsSmallBuffer(a4),a5
  1012.     btst    #dof_LONG,d3
  1013.     bne.s    .Long
  1014.     moveq    #16-1,d2
  1015.     move.w    (a2)+,d0
  1016.     swap    d0
  1017.     bra.s    .001
  1018. .Long    moveq    #32-1,d2
  1019.     move.l    (a2)+,d0
  1020.  
  1021. .001    btst    #dof_ZERO,d3
  1022.     bne.s    .002
  1023. .ZLoop    rol.l    #1,d0
  1024.     dbcs    d2,.ZLoop
  1025.     tst.w    d2
  1026.     bpl.s    .003
  1027.     move.b    #'0',(a5)+
  1028.     moveq    #0,d5
  1029.     bra.s    .004
  1030.  
  1031. .003    move.w    d2,d5
  1032.     bra.s    .005
  1033. .002    move.w    d2,d5
  1034. .Loop    rol.l    #1,d0
  1035.     bcs.s    .005
  1036.     move.b    #'0',(a5)+
  1037.     dbra    d2,.Loop
  1038.     bra.s    .004
  1039. .005    move.b    #'1',(a5)+
  1040.     dbra    d2,.Loop
  1041.  
  1042. .004    lea    vsSmallBuffer(a4),a5
  1043.     move.w    d5,d0
  1044.     addq.w    #1,d0
  1045.     bra    PartyDudes
  1046.  
  1047. ;------------------------------------------------------------------
  1048. ;DopeEFloat:
  1049. ;    bra    DopeError
  1050. ;DopeFFloat:
  1051. ;    bra    DopeError
  1052. ;DopeGFloat:
  1053. ;    bra    DopeError
  1054.  
  1055. ;------------------------------------------------------------------
  1056. ;IN    d0.w    = StringPart Length
  1057. ;    d3.l    = Flags
  1058. ;    a3.l    = ^Text
  1059. ;    a5.l    = ^StringPart to insert
  1060.  
  1061. PartyDudes:
  1062.     move.w    vwFieldSize(a4),d7
  1063.     move.w    vwLenSize(a4),d6
  1064.     beq.s    .001
  1065.     cmp.w    d6,d0
  1066.     bhi.s    .002
  1067. .001    move.w    d0,d6
  1068. .002    sub.w    d6,d7
  1069.     bpl.s    .003
  1070.     moveq    #0,d7
  1071.  
  1072. ; d6.w    = Put Length
  1073. ; d7.w    = Pad Length
  1074.  
  1075. .003    btst    #dof_MINUS,d3
  1076.     bne.s    PostPad
  1077.  
  1078. PrePad:
  1079.     move.b    cnh_PadSpace(a0),d0    ;DoPadding
  1080.     btst    #dof_ZERO,d3
  1081.     beq.s    .001
  1082.     move.b    cnh_PadZero(a0),d0
  1083.     bra.s    .001
  1084. .PLoop    bsr    PutCharFunc
  1085. .001    dbra    d7,.PLoop
  1086.     bra.s    .002            ;DoPutString
  1087. .SLoop    move.b    (a5)+,d0
  1088.     beq.s    .003
  1089.     bsr    PutCharFunc
  1090. .002    dbra    d6,.SLoop
  1091. .003    rts
  1092.  
  1093. PostPad:
  1094.     bra.s    .002            ;DoPutString
  1095. .PLoop    move.b    (a5)+,d0
  1096.     beq.s    .003
  1097.     bsr    PutCharFunc
  1098. .002    dbra    d6,.PLoop
  1099. .003    move.b    cnh_PadSpace(a0),d0    ;DoPadding
  1100.     btst    #dof_ZERO,d3
  1101.     beq.s    .001
  1102.     move.b    cnh_PadZero(a0),d0
  1103.     bra.s    .001
  1104. .SLoop    bsr    PutCharFunc
  1105. .001    dbra    d7,.SLoop
  1106.     rts
  1107.  
  1108. ;------------------------------------------------------------------
  1109. ;OUT    d0.w    = Success
  1110.  
  1111. DoBackSlash:
  1112.     move.b    (a1)+,d0
  1113.     cmp.b    #'n',d0        ;LineFeed
  1114.     beq.w    .LF
  1115.     cmp.b    #'t',d0        ;Tabulator
  1116.     beq.w    .Tab
  1117.     cmp.b    #'\',d0        ;BackSlash
  1118.     beq    PutCharFunc
  1119.     cmp.b    #'f',d0        ;FormFeed
  1120.     beq.w    .FF
  1121.     cmp.b    #'b',d0        ;BackSpace
  1122.     beq.w    .BS
  1123.     cmp.b    #'#',d0        ;Hash
  1124.     beq.w    .User
  1125.     cmp.b    #'@',d0        ;Plain Style
  1126.     beq.w    .Plain
  1127.     cmp.b    #'B',d0        ;Bold Style
  1128.     beq.w    .Bold
  1129.     cmp.b    #'I',d0        ;Italic Style
  1130.     beq.w    .Italic
  1131.     cmp.b    #'U',d0        ;Underline Style
  1132.     beq.w    .Under
  1133.     cmp.b    #'C',d0        ;Foreground Color
  1134.     beq.w    .FColor
  1135.     cmp.b    #'Z',d0        ;Background Color
  1136.     beq    .BColor
  1137.     cmp.b    #'[',d0        ;Escape
  1138.     beq    .Escape
  1139.     cmp.b    #'{',d0        ;CSI
  1140.     beq.w    .Csi
  1141.     cmp.b    #'r',d0        ;Return
  1142.     beq.s    .Rtn
  1143.     cmp.b    #'v',d0        ;Vert. Tabulator
  1144.     beq.s    .Vtab
  1145.                 ;--- Examine for ASCII
  1146.     bsr    GetNumber
  1147.     tst.w    d1
  1148.     bpl    PutCharFunc
  1149. .Error    move.w    #FALSE,vwSuccess(a4)
  1150. .Xit    rts
  1151.  
  1152. .LF    move.b    #10,d0
  1153.     bra    PutCharFunc
  1154. .Tab    move.b    #9,d0
  1155.     bra    PutCharFunc
  1156. .FF    move.b    #12,d0
  1157.     bra    PutCharFunc
  1158. .BS    move.b    #8,d0
  1159.     bra    PutCharFunc
  1160. .Rtn    move.b    #13,d0
  1161.     bra    PutCharFunc
  1162. .Vtab    move.b    #11,d0
  1163.     bra    PutCharFunc
  1164.  
  1165. .User    moveq    #0,d0
  1166.     move.b    (a1)+,d0
  1167.     sub.b    #'1',d0
  1168.     blt.s    .Error
  1169.     cmp.b    #8,d0
  1170.     bge.s    .Error
  1171.     add.w    d0,d0
  1172.     add.w    d0,d0
  1173.     lea    cnh_UserNotes(a0),a5
  1174.     move.l    (a5,d0.w),d0
  1175.     beq.s    .Xit
  1176.     move.l    d0,a5
  1177.     bra.s    DoCopyString
  1178.  
  1179. .Plain    lea    sDoStyle1(pc),a5
  1180.     bra.s    DoCopyString
  1181. .Bold    lea    sDoStyle2(pc),a5
  1182.     bra.s    DoCopyString
  1183. .Italic    lea    sDoStyle3(pc),a5
  1184.     bra.s    DoCopyString
  1185. .Under    lea    sDoStyle4(pc),a5
  1186.     bra.s    DoCopyString
  1187.  
  1188. .BColor    lea    sDoBgCol(pc),a5
  1189.     bra    .Color
  1190. .FColor    lea    sDoFgCol(pc),a5
  1191. .Color    move.b    (a1)+,3(a5)
  1192.     bra    DoCopyString
  1193.  
  1194. .Escape    move.b    #27,d0
  1195.     bra    PutCharFunc
  1196. .Csi    move.b    #155,d0
  1197.     bra    PutCharFunc
  1198.  
  1199. ;------------------------------------------------------------------
  1200. ;IN    a3.l    = ^Text
  1201. ;    a5.l    = ^StringPart
  1202.  
  1203. DoCopyString:
  1204.     move.b    (a5)+,d0
  1205.     beq.s    .Exit
  1206.     bsr    PutCharFunc
  1207.     bra.s    DoCopyString
  1208. .Exit    rts
  1209.  
  1210. ;------------------------------------------------------------------
  1211. ;IN    d0.b    = First Char
  1212. ;    a1.l    = ^String
  1213. ;OUT    d0.w    = Number
  1214. ;    d1.l    = Success
  1215.  
  1216. GetNumber:
  1217.     cmp.b    #'*',d0        ;get number from args?
  1218.     beq.s    .Var
  1219.     cmp.b    #'0',d0        ;one digit?
  1220.     blt.s    .Error
  1221.     cmp.b    #'9',d0
  1222.     bgt.s    .Error
  1223.     moveq    #0,d1
  1224.     and.w    #$000f,d0
  1225.     move.w    d0,d1
  1226.     move.b    (a1),d0
  1227.     cmp.b    #'0',d0        ;two digits?
  1228.     blt.s    .NoMore
  1229.     cmp.b    #'9',d0
  1230.     bgt.s    .NoMore
  1231.     addq.l    #1,a1
  1232.     mulu    #10,d1        ;use shift *10
  1233.     and.w    #$000f,d0
  1234.     add.w    d0,d1
  1235.     move.b    (a1),d0
  1236.     cmp.b    #'0',d0        ;three digits?
  1237.     blt.s    .NoMore
  1238.     cmp.b    #'9',d0
  1239.     bgt.s    .NoMore
  1240.     addq.l    #1,a1
  1241.     mulu    #10,d1        ;as above
  1242.     and.w    #$000f,d0
  1243.     add.w    d0,d1
  1244. .NoMore    move.w    d1,d0
  1245.     moveq    #0,d1
  1246.     rts
  1247. .Error    moveq    #-1,d1
  1248.     rts
  1249. .Var    move.w    (a2)+,d0
  1250.     and.w    #$00ff,d0
  1251.     moveq    #0,d1
  1252.     rts
  1253.  
  1254. ;------------------------------------------------------------------
  1255. ;    @DefineChars
  1256. ;------------------------------------------------------------------
  1257. ;
  1258. ; Define specified CharTable according to Mode:
  1259. ;
  1260. ;    CASE Mode OF
  1261. ;      1: .new
  1262. ;      2: .add
  1263. ;      3: .rem
  1264. ;      4: .get
  1265. ;    OTHERWISE
  1266. ;      .all
  1267. ;    ENDCASE
  1268. ;
  1269. ;------------------------------------------------------------------
  1270. ; IN    d0.l    = Mode
  1271. ;    a1.l    = ^CharTable
  1272. ;    a2.l    = ^ArrayOfChars
  1273. ; OUT    { CharTable modified }
  1274. ;------------------------------------------------------------------
  1275.  
  1276. DefineChars:
  1277.     move.l    a2,a0
  1278.     subq.w    #1,d0
  1279.     beq.s    .New
  1280.     subq.w    #1,d0
  1281.     beq.s    .Add
  1282.     subq.w    #1,d0
  1283.     beq.s    .Rem
  1284.     subq.w    #1,d0
  1285.     beq.s    .Get
  1286. ;------------------------------------------------------------------
  1287. .All    moveq    #0,d0            ;--- DEFMODE_ALL
  1288.     bra.s    .Get
  1289. .Exit    rts
  1290.  
  1291. ;------------------------------------------------------------------
  1292. .New    move.l    a1,d0            ;--- DEFMODE_NEW
  1293.     move.w    #[CHARDEFSIZE/4]-1,d1
  1294. .NLoop    clr.l    (a1)+
  1295.     dbra    d1,.NLoop
  1296.     move.l    d0,a1            ;continue down though...
  1297. ;------------------------------------------------------------------
  1298. .Add    moveq    #0,d0            ;--- DEFMODE_ADD
  1299.     move.b    (a0)+,d0
  1300.     beq.s    .Exit
  1301.     move.w    d0,d1
  1302.     lsr.w    #3,d0
  1303.     not.w    d1
  1304.     and.w    #$0007,d1
  1305.     bset    d1,(a1,d0.w)
  1306.     bra.s    .Add
  1307.  
  1308. ;------------------------------------------------------------------
  1309. .Rem    moveq    #0,d0            ;--- DEFMODE_REM
  1310.     move.b    (a0)+,d0
  1311.     beq.s    .Exit
  1312.     move.w    d0,d1
  1313.     lsr.w    #3,d0
  1314.     not.w    d1
  1315.     and.w    #$07,d1
  1316.     bclr    d1,(a1,d0.w)
  1317.     bra.s    .Rem
  1318.  
  1319. ;------------------------------------------------------------------
  1320. .Get    swap    d0            ;--- DEFMODE_GET
  1321.     lea    awDefDefTable(pc),a0
  1322.     adda.w    (a0,d0.w),a0
  1323.     REPT    CHARDEFSIZE/4
  1324.     move.l    (a0)+,(a1)+
  1325.     ENDR
  1326.     rts
  1327.  
  1328. ;------------------------------------------------------------------
  1329. ;    @Display
  1330. ;------------------------------------------------------------------
  1331. ;
  1332. ; Format and Display a text string in a Console Window.
  1333. ;
  1334. ; Length for DoFormat calculated.
  1335. ;
  1336. ; Cursor turn off during display.
  1337. ;
  1338. ;------------------------------------------------------------------
  1339. ; IN    d0.l    = MaxLen
  1340. ;    a0.l    = ConHandle
  1341. ;    a1.l    = ^String
  1342. ;    a2.l    = ^List of Arguments
  1343. ; OUT    -
  1344. ;------------------------------------------------------------------
  1345.  
  1346. Display:
  1347.     PUSH    d7/a3
  1348.     move.l    d0,d7
  1349.     move.l    a1,a3            ;--- FIND LENGTH OF TEXT
  1350.     moveq    #-1,d0
  1351. .Loop    tst.b    (a3)+
  1352.     dbeq    d0,.Loop
  1353.     neg.l    d0
  1354.     subq.w    #1,d0
  1355.     cmp.w    d7,d0            ;can't be bigger than MaxLen
  1356.     ble.s    .Less
  1357.     move.w    d7,d0
  1358. .Less    add.w    cnh_ExLength(a0),d0    ;+ additional space
  1359.     ABSW    d0            ;align
  1360.  
  1361.     DLINK    a4,d0            ;--- ALLOC SPACE FOR TEXTBUFFER ON STACK
  1362.     move.l    sp,a3            ;point to start
  1363.     move.l    #$9b302070,(a3)+    ;Cursor off
  1364.     bsr    DoFormat        ;--- FORMAT STRING AND DISPLAY IT
  1365.     subq.l    #4,d0
  1366.     move.l    d0,a1
  1367.     move.l    d7,d0
  1368.     bsr.s    DisplayRaw
  1369.     unlk    a4
  1370.     move.w    cnh_CursorStatus(a0),d0
  1371.     bsr    Cursor
  1372.     PULL    d7/a3
  1373.     rts
  1374.  
  1375. ;------------------------------------------------------------------
  1376. ;    @DisplayRaw
  1377. ;------------------------------------------------------------------
  1378. ;
  1379. ; Display an unformatted text string in a Console Window.
  1380. ;
  1381. ;------------------------------------------------------------------
  1382. ; IN    d0.l    = MaxLen [ -1 don't care ]
  1383. ;    a0.l    = ConHandle
  1384. ;    a1.l    = ^Text
  1385. ; OUT    -
  1386. ;------------------------------------------------------------------
  1387.  
  1388. DisplayRaw:
  1389.     PUSH    d1/a0/a1/a6
  1390.     move.l    cnh_WriteIO(a0),a6
  1391.     move.w    #CMD_WRITE,IO_COMMAND(a6)
  1392.     move.l    a1,IO_DATA(a6)
  1393.     move.l    d0,IO_LENGTH(a6)
  1394.     lea    dWriteReplyPort(pc),a0
  1395.     move.l    a0,MN_REPLYPORT(a6)
  1396.     move.l    a6,a1
  1397.     move.l    pSysBase(pc),a6
  1398.     CALL    DoIO
  1399.     PULL    d1/a0/a1/a6
  1400.     rts
  1401.  
  1402. ;------------------------------------------------------------------
  1403. ;    @Accept
  1404. ;------------------------------------------------------------------
  1405. ;
  1406. ; Accept an input from user.
  1407. ;
  1408. ;------------------------------------------------------------------
  1409. ; IN    d0.l    = Flags
  1410. ;    a0.l    = ConHandle
  1411. ;    a1.l    = ^AcceptStructure
  1412. ; OUT    d0.l    = Success
  1413. ;            [ -1 = Error    ]
  1414. ;            [  0 = OK    ]
  1415. ;            [  1 = ExitFlag    ]
  1416. ;            [  2 = ExitChar    ]
  1417. ;
  1418. ; GLOBALS
  1419. ;    d6.l    = Flags
  1420. ;    a2.l    = ^AcceptStructure
  1421. ;    a3.l    = ConHandle
  1422. ;    a4.l    = ^StackBuffer
  1423. ;    a5.l    = ^Message
  1424. ;    a6.l    = SysBase
  1425. ;
  1426. ;------------------------------------------------------------------
  1427.  
  1428. ;---  THE ACCEPT STACK BUFFER
  1429. vsBufferEnd    SET    0
  1430. vsBuffer    SET    vsBufferEnd-cAcceptBufferSize
  1431. vdInputEvent    SET    vsBuffer-ie_SIZEOF
  1432. vAcceptSizeOf    SET    vdInputEvent
  1433.  
  1434. Accept:
  1435.     PUSH    vir
  1436.                     ;--- ASSIGN THE GLOBAL REGISTERS
  1437.     link    a4,#vAcceptSizeOf    ;StackBuffer
  1438.     move.l    a0,a3            ;ConHandle
  1439.     move.l    a1,a2            ;AcceptStructure
  1440.     move.l    d0,d6            ;Flags
  1441.     move.l    pSysBase(pc),a6    ;ExecBase
  1442.  
  1443.     and.l    #~[RAWKEY!VANILLAKEY],acc_ExitFlags(a2)    ;Illegal as ExitFlags
  1444.  
  1445.     bsr.s    EraseKeyBuffer        ;--- ERASE MESSAGE BUFFER IF REQUIRED
  1446.     bsr.s    AcceptKey        ;--- GO FOR IT
  1447.     tst.l    d0
  1448.     bpl.s    .Exit            ;Error?
  1449.     clr.b    acc_Char(a2)        ;YES! No key
  1450. .Exit    unlk    a4
  1451.     PULL    vir
  1452.     rts
  1453.  
  1454. ;------------------------------------------------------------------
  1455. EraseKeyBuffer:
  1456.     btst    #ACCB_ERASE,d6
  1457.     beq.s    .Exit
  1458. .EraseLoop
  1459.     move.l    cnh_UserPort(a3),a0    ;Erase keybuffer
  1460.     CALL    GetMsg
  1461.     tst.l    d0
  1462.     beq.s    .Exit
  1463.     move.l    d0,a1
  1464.     CALL    ReplyMsg
  1465.     bra.s    .EraseLoop
  1466. .Exit    rts
  1467.  
  1468. ;------------------------------------------------------------------
  1469. ;IN    a3.l    = ConHandle
  1470. ;    a2.l    = AcceptStructure
  1471. ;OUT    d0.l    = Success [ see @Accept Header ]
  1472.  
  1473. AcceptError:                ;--- ERROR IN ACCEPT
  1474.     RETURN    -1
  1475.  
  1476. AcceptKey:                ;--- ACCEPT A KEYSTROKE
  1477.     bsr    GetMessage
  1478.     beq.s    .AccOn
  1479.     bmi.s    AcceptError
  1480.     move.l    cnh_MsgHandler(a3),d1    ;--- MESSAGE HANDLER
  1481.     beq.s    .Exit
  1482.     PUSH    d1-d7/a0-a6
  1483.     move.l    a0,d0
  1484.     move.l    d1,a5
  1485.     jsr    (a5)
  1486.     PULL    d1-d7/a0-a6
  1487.     tst.l    d0
  1488.     beq.s    AcceptKey
  1489. .Exit    clr.b    acc_Char(a2)
  1490.     rts
  1491. .AccOn    bsr    KeyWays
  1492.     bmi.s    AcceptError
  1493.     beq.s    HandleChar
  1494. HandleRawKey:                ;--- HANDLE A RAWKEY
  1495.     clr.b    acc_Char(a2)        ;RawKey found in acc_Code
  1496.     RETURN
  1497.  
  1498. HandleChar:
  1499.     bsr    ConvertChar        ;--- HANDLE CHAR
  1500.     move.b    d0,acc_Char(a2)
  1501.     lea    acc_ExitTable(a2),a0    ;Is it a ExitChar?
  1502.     bsr    TestChar
  1503.     beq.s    .Exit
  1504.     lea    acc_ValidTable(a2),a0    ;Is it a ValidChar?
  1505.     bsr    TestChar
  1506.     bne.w    AcceptKey
  1507.     bsr    EchoChar
  1508.     RETURN
  1509. .Exit    bsr    EchoChar
  1510.     RETURN    2
  1511.  
  1512. ;------------------------------------------------------------------
  1513. ;OUT    d0.l    = Success
  1514. ;            -1 = Error [no Msg on ~ACCB_WAIT]
  1515. ;             0 = OK
  1516. ;             1 = ExitFlags
  1517. ;    CCR    = Success
  1518. ;    a0.l    = ^Msg
  1519.  
  1520. GetMessage:
  1521.     move.l    cnh_UserPort(a3),a0    ;--- GET MESSAGE
  1522.     CALL    GetMsg
  1523.     tst.l    d0
  1524.     bne.s    .GotCha
  1525.     btst    #ACCB_WAIT,d6
  1526.     beq.s    .NoWait            ;Exit if no message and no wait
  1527.     move.l    cnh_Signal(a3),d0    ;--- WAIT FOR MESSAGE
  1528.     CALL    Wait
  1529.     bra.s    GetMessage
  1530. .NoWait    RETURN    -1
  1531. .GotCha    move.l    d0,a0
  1532.     lea    im_Class(a0),a0        ;Copy message
  1533.     lea    acc_Class(a2),a1
  1534.     move.l    (a0)+,(a1)+
  1535.     move.l    (a0)+,(a1)+
  1536.     move.l    (a0)+,(a1)+
  1537.     move.l    (a0)+,(a1)+
  1538.     move.l    (a0)+,(a1)+
  1539.     move.l    (a0)+,(a1)+
  1540.     move.l    (a0)+,(a1)+
  1541.     move.l    d0,a1            ;--- REPLY MESSAGE
  1542.     CALL    ReplyMsg
  1543.     move.l    acc_Class(a2),d0    ;--- WHAT KIND OF MESSAGE
  1544.     cmp.l    #RAWKEY,d0        ;Is it RAWKEY?
  1545.     bne.s    .001
  1546.     RETURN
  1547. .001    and.l    acc_ExitFlags(a2),d0    ;Ignore everything else but ExitFlags
  1548.     beq.s    GetMessage
  1549.     RETURN    1
  1550.  
  1551. ;------------------------------------------------------------------
  1552. ;OUT    d0.l    = Success
  1553. ;            -1 = Error
  1554. ;             0 = OK (Handle)
  1555. ;             1 = RawKey
  1556. ;    CCR    = Success
  1557.  
  1558. KeyWays:
  1559.     move.w    acc_Code(a2),d0        ;--- MESSAGE IS RAWKEY
  1560.     btst    #ACCB_RAWKEY,d6
  1561.     bne.s    .Raw
  1562.     btst    #ACCB_DUALKEY,d6
  1563.     bne.s    .Handle
  1564.     tst.b    d0            ;--- UPKEY
  1565.     bpl.s    .Down
  1566.     btst    #ACCB_UPKEY,d6
  1567.     bne.s    .Handle
  1568. .Error    RETURN    -1
  1569. .Down    btst    #ACCB_UPKEY,d6        ;wait for key to be released?
  1570.     bne.s    .Error
  1571. .Handle    RETURN    0
  1572. .Raw    RETURN    1
  1573.  
  1574.  
  1575. ;------------------------------------------------------------------
  1576. EchoChar:
  1577.     btst    #ACCB_ECHO,d6        ;--- ECHOCHAR
  1578.     beq.s    .Exit
  1579.     lea    cnh_EchoTable(a3),a0
  1580.     bsr    TestChar
  1581.     bne.s    .Exit
  1582.     lea    vsBuffer(a4),a0
  1583.     moveq    #1,d0
  1584.     move.l    a0,a1            ;Text
  1585.     move.l    a3,a0            ;ConHandle
  1586.     bra    DisplayRaw
  1587. .Exit    rts
  1588.  
  1589. ;------------------------------------------------------------------
  1590. ;IN    a0.l    = Table to test
  1591. ;OUT    d0.l    = Success
  1592. ;    CCR
  1593.  
  1594. TestChar:
  1595.     moveq    #0,d0
  1596.     move.b    acc_Char(a2),d0
  1597.     moveq    #0,d1
  1598.     move.w    d0,d1
  1599.     lsr.w    #3,d0
  1600.     not.w    d1
  1601.     and.w    #$0007,d1
  1602.     btst    d1,(a0,d0.w)        ;test appropriate bit
  1603.     beq.s    .Error
  1604.     RETURN    TRUE
  1605. .Error    RETURN    FALSE
  1606.  
  1607. ;------------------------------------------------------------------
  1608. ; IN    a0.l    = ^Message
  1609. ; OUT    d0.b    = Char
  1610. ;          ! Error [ 0 ]
  1611.  
  1612. abConvertArray:
  1613.     dc.b    AKEY_BS,0,0,0,AKEY_ESC,AKEY_DEL,0
  1614.     dc.b    0,0,0,0,AKEY_ARROWUP,AKEY_ARROWDN,AKEY_ARROWRG,AKEY_ARROWLF
  1615.     dc.b    AKEY_F1,AKEY_F2,AKEY_F3,AKEY_F4,AKEY_F5
  1616.     dc.b    AKEY_F6,AKEY_F7,AKEY_F8,AKEY_F9,AKEY_F10
  1617.     dc.b    0,0,0,0,0,AKEY_HELP
  1618.     EVEN
  1619.  
  1620. ConvertChar:
  1621.     PUSH    d1/a0/a1/a2/a5/a6
  1622.     move.w    acc_Code(a2),d0
  1623.     and.w    #$007f,d0
  1624.     sub.b    #$41,d0
  1625.     blt.s    .Convert
  1626.     cmp.b    #$60-$41,d0
  1627.     bge.s    .Error
  1628.     move.b    abConvertArray(pc,d0.w),d0
  1629.     beq.s    .Convert
  1630.     bra.s    .Exit
  1631. .Convert
  1632.     lea    vdInputEvent(a4),a0    ;InputEvent Structure
  1633.     clr.l    ie_NextEvent(a0)
  1634.     move.w    #IECLASS_RAWKEY<<8,ie_Class(a0)
  1635.     move.w    acc_Code(a2),ie_Code(a0)
  1636.     move.w    acc_Qualifier(a2),ie_Qualifier(a0)
  1637.     move.l    acc_IAddress(a2),a1
  1638.     move.l    (a1),ie_EventAddress(a0)
  1639.     lea    vsBuffer(a4),a1        ;CharBuffer (destination)
  1640.     suba.l    a2,a2            ;default keymap
  1641.     moveq    #4,d1            ;length
  1642.     move.l    cnh_CDBase(a3),a6
  1643.     CALL    RawKeyConvert
  1644.     subq.w    #1,d0            ;skip if more than 1 char was converted
  1645.     bne.s    .Error
  1646.     lea    vsBuffer(a4),a1
  1647.     move.b    (a1),d0
  1648. .Exit    PULL    d1/a0/a1/a2/a5/a6
  1649.     rts
  1650. .Error    moveq    #0,d0
  1651.     bra.s    .Exit
  1652.  
  1653.  
  1654. ;------------------------------------------------------------------
  1655. ;    @AcceptString
  1656. ;------------------------------------------------------------------
  1657. ;
  1658. ; Accept the input of a string from user.
  1659. ;
  1660. ;------------------------------------------------------------------
  1661. ; IN    d0.l    = Flags
  1662. ;    a0.l    = ConHandle
  1663. ;    a1.l    = ^AcceptStructure
  1664. ; OUT    d0.l    = Success
  1665. ;
  1666. ; GLOBALS
  1667. ;    d6.l    = Flags
  1668. ;    a2.l    = ^AcceptStructure
  1669. ;    a3.l    = ConHandle
  1670. ;    a4.l    = ^StackBuffer
  1671. ;    a6.l    = SysBase
  1672. ;
  1673. ;------------------------------------------------------------------
  1674.  
  1675. ;---  EXTENTION OF THE ACCEPT STACK BUFFER
  1676. vsJustBuffer    SET    vAcceptSizeOf-16
  1677. vwStyle        SET    vsJustBuffer-2
  1678. vwFgCol        SET    vwStyle-2
  1679. vwBgCol        SET    vwFgCol-2
  1680. vSizeOf        SET    vwBgCol
  1681.  
  1682.  
  1683. AcceptString:
  1684.     PUSH    vir
  1685.                     ;--- ASSIGN THE GLOBAL REGISTERS
  1686.     link    a4,#vSizeOf    ;StackBuffer
  1687.     move.l    a0,a3        ;ConHandle
  1688.     move.l    a1,a2        ;AcceptStructure
  1689.     move.l    d0,d6        ;Flags
  1690.     move.l    pSysBase(pc),a6    ;ExecBase
  1691.  
  1692.     and.l    #~[RAWKEY!VANILLAKEY],acc_ExitFlags(a2)    ;Illegal as ExitFlags
  1693.  
  1694.     move.w    cnh_ExLength(a3),d0    ;--- Ensure that ExLength > MaxLength
  1695.     sub.w    accs_MaxLength(a2),d0
  1696.     blt.s    .111
  1697.     neg.w    d0
  1698.     add.w    d0,cnh_ExLength(a3)
  1699. .111
  1700.     lea    -cin_SIZEOF(sp),sp    ;Alloc space for info!
  1701.     move.l    sp,a1
  1702.     move.l    a3,a0
  1703.     bsr    GetInfo
  1704.     move.l    d0,a1            ;--- STORE OLD GFX
  1705.     move.w    cin_Styles(a1),vwStyle(a4)
  1706.     move.w    cin_FgCol(a1),vwFgCol(a4)
  1707.     move.w    cin_BgCol(a1),vwBgCol(a4)
  1708.     tst.w    acc_XStart(a2)        ;--- SET START POSITION
  1709.     bpl.s    .001
  1710.     move.w    cin_XPos(a1),acc_XStart(a2)
  1711. .001    tst.w    acc_YStart(a2)
  1712.     bpl.s    .002
  1713.     move.w    cin_YPos(a1),acc_YStart(a2)
  1714. .002    move.w    cin_XSize(a1),d1    ;--- CORRECT MAXLENGTH
  1715.     lea    cin_SIZEOF(sp),sp    ;Dealloc space!
  1716.     move.w    acc_XStart(a2),d0
  1717.     add.w    accs_FieldLen(a2),d0
  1718.     cmp.w    d1,d0
  1719.     ble.s    .003
  1720.     sub.w    acc_XStart(a2),d1
  1721.     ble.s    .Exit            ;exit if FieldLen <= 0
  1722.     move.w    d1,accs_FieldLen(a2)
  1723. .003
  1724.     move.w    acc_Styles(a2),d0    ;--- SET Styles, FgCol and BgCol
  1725.     bpl.s    .200
  1726.     move.w    vwStyle(a4),d0
  1727. .200    move.w    acc_FgCol(a2),d1
  1728.     bpl.s    .201
  1729.     move.w    vwFgCol(a4),d1
  1730. .201    move.w    acc_BgCol(a2),d2
  1731.     bpl.s    .202
  1732.     move.w    vwBgCol(a4),d2
  1733. .202    move.l    a3,a0
  1734.     bsr    SetGfx
  1735.  
  1736.     bsr    EraseKeyBuffer        ;--- ERASE KEYBOARD BUFFER IF REQUIRED
  1737.     bsr    AcceptString2
  1738.  
  1739. .Exit    move.l    d0,-(sp)
  1740.     move.w    vwStyle(a4),d0        ;--- RESTORE OLD GFX AND LEAVE
  1741.     move.w    vwFgCol(a4),d1
  1742.     move.w    vwBgCol(a4),d2
  1743.     move.l    a3,a0
  1744.     bsr    SetGfx
  1745.     move.l    (sp)+,d0
  1746.     unlk    a4
  1747.     PULL    vir
  1748.     rts
  1749.  
  1750. ;------------------------------------------------------------------
  1751. ;IN    a3.l    = ConHandle
  1752. ;    a2.l    = AcceptStructure
  1753. ;OUT    d0.l    = Success
  1754. ;            -1 = Error
  1755. ;             0 = OK
  1756. ;             1 = ExitFlag
  1757.  
  1758. VALIDQUAL    SET    $8000!IEQUALIFIER_CAPSLOCK
  1759. VALIDQUAL    SET    VALIDQUAL!IEQUALIFIER_REPEAT
  1760. VALIDQUAL    SET    VALIDQUAL!IEQUALIFIER_NUMERICPAD
  1761. VALIDQUAL    SET    VALIDQUAL!IEQUALIFIER_SHIFT
  1762.  
  1763. AcceptString2:
  1764.     move.w    accs_MaxLength(a2),d0    ;ensure than FieldLen <= MaxLen
  1765.     cmp.w    accs_FieldLen(a2),d0
  1766.     ble.s    .001
  1767.     btst    #ACCB_NOSCROLL,d6
  1768.     beq.s    .002
  1769.     move.w    accs_FieldLen(a2),accs_MaxLength(a2)
  1770.     bra.s    .002
  1771. .001    move.w    d0,accs_FieldLen(a2)
  1772. .002    btst    #ACCB_CONTINUE,d6
  1773.     bne.s    .003
  1774.     clr.w    accs_Position(a2)    ;--- RESTART STRING
  1775.     clr.w    accs_Length(a2)
  1776.     clr.w    accs_DispPos(a2)
  1777.     btst    #ACCB_NOAMIGA,d6
  1778.     bne.s    .002
  1779.     move.l    accs_InputBuffer(a2),a0    ;--- COPY STRING TO BUFFER
  1780.     move.l    accs_WorkBuffer(a2),d0
  1781.     beq.s    .003
  1782.     move.l    d0,a1
  1783.     move.w    accs_MaxLength(a2),d0
  1784.     subq.w    #1,d0
  1785. .CopyLoop
  1786.     move.b    (a0)+,(a1)+
  1787.     dbra    d0,.CopyLoop
  1788.  
  1789. .003    or.l    #[ACCF_WAIT],d6
  1790.     and.l    #~[ACCF_ECHO!ACCF_UPKEY!ACCF_RAWKEY!ACCF_DUALKEY],d6
  1791.     bsr    PrepareEcho
  1792.  
  1793. StringLoop:
  1794.     bsr    EchoBuffer
  1795.     move.w    accs_MaxLength(a2),d1    ;--- TEST LASTEXIT FLAG
  1796.     cmp.w    accs_Length(a2),d1
  1797.     bgt.s    StringAgain
  1798.     btst    #ACCB_LASTEXIT,d6
  1799.     bne.w    StringExitchar
  1800. StringAgain:
  1801.     bsr    GetMessage
  1802.     beq.s    StringGo
  1803. StringEnd:                ;Stop if ExitFlags or Error
  1804.     bmi.s    .Exit
  1805.     move.l    cnh_MsgHandler(a3),d1    ;Hey, hold on... Let's see if
  1806.     beq.s    .Exit            ;there's a handler to jump to.
  1807.     PUSH    d1-d7/a0-a6
  1808.     move.l    a0,d0            ;message
  1809.     move.l    d1,a5
  1810.     jsr    (a5)
  1811.     PULL    d1-d7/a0-a6
  1812.     tst.l    d0
  1813.     beq.s    StringAgain
  1814. .Exit    clr.b    acc_Char(a2)
  1815.     rts
  1816.  
  1817. StringGo:
  1818.     bsr    KeyWays
  1819.     bmi.s    StringAgain
  1820.     bsr    ConvertChar
  1821.     move.b    d0,acc_Char(a2)
  1822.     beq.s    StringAgain        ;Back if Qualifier or Error
  1823.  
  1824.     move.w    acc_Qualifier(a2),d1
  1825.     and.w    #~VALIDQUAL,d1
  1826.     bne.s    .001
  1827.     move.w    acc_Qualifier(a2),d1
  1828.     and.w    #IEQUALIFIER_SHIFT,d1
  1829.     bne.s    .002
  1830.     cmp.b    #AKEY_BS,d0        ;BackSpace
  1831.     beq    KeyBackSpace
  1832.     cmp.b    #AKEY_DEL,d0        ;Delete
  1833.     beq    KeyDelete
  1834.     cmp.b    #AKEY_ARROWRG,d0    ;Cursor Right
  1835.     beq    KeyCRight
  1836.     cmp.b    #AKEY_ARROWLF,d0    ;Cursor Left
  1837.     beq    KeyCLeft
  1838.     bra.s    .001
  1839.  
  1840. .002    cmp.b    #AKEY_ARROWRG,d0    ;Shift Cursor Right
  1841.     beq    KeySCRight
  1842.     cmp.b    #AKEY_ARROWLF,d0    ;Shift Cursor Left
  1843.     beq    KeySCLeft
  1844.  
  1845. .001    move.w    acc_Qualifier(a2),d1
  1846.     and.w    #IEQUALIFIER_COMMAND,d1
  1847.     beq.s    StringConvert
  1848.     btst    #ACCB_NOAMIGA,d6
  1849.     bne.s    StringConvert
  1850.     move.b    acc_Char(a2),d0
  1851.     cmp.b    #'q',d0
  1852.     beq    KeyRestore
  1853.     cmp.b    #'x',d0
  1854.     beq    KeyClearLine
  1855.     btst    #ACCB_NOSTDAMIGA,d6
  1856.     bne.s    StringConvert
  1857.     cmp.b    #'y',d0
  1858.     beq    KeyClearEOL
  1859.     cmp.b    #'a',d0
  1860.     beq    KeyToggle
  1861.  
  1862. StringConvert:
  1863.     lea    acc_ExitTable(a2),a0    ;--- TEST FOR EXITCHAR
  1864.     bsr    TestChar
  1865.     beq.s    StringExitchar
  1866.     lea    acc_ValidTable(a2),a0    ;--- TEST FOR VALIDCHAR
  1867.     bsr    TestChar
  1868.     bne    StringAgain
  1869.  
  1870.     btst    #ACCB_FULLSTOP,d6    ;--- TEST FULLSTOP FLAG
  1871.     beq.s    .001
  1872.     btst    #ACCB_OVERWRITE,d6    ;but only if we're in insert mode
  1873.     bne.s    .001
  1874.     move.w    accs_Length(a2),d1
  1875.     cmp.w    accs_MaxLength(a2),d1
  1876.     bge    StringAgain
  1877. .001    bsr    CopyChar2Buffer        ;--- COPY ValidChar TO BUFFER
  1878.     bra.w    StringLoop
  1879. StringExitchar:
  1880.     RETURN    TRUE
  1881.  
  1882. ;------------------------------------------------------------------
  1883. KeyBackSpace:                ;--- BackSpace
  1884.     move.l    accs_InputBuffer(a2),a0
  1885.     move.w    accs_Position(a2),d0
  1886.     beq    StringAgain
  1887.     subq.w    #1,d0
  1888.     move.w    d0,accs_Position(a2)
  1889.     bsr    AdjustField
  1890.     move.w    accs_Length(a2),d1
  1891.     bra.s    KeyDel
  1892. KeyDelete:                ;--- <DEL>
  1893.     move.l    accs_InputBuffer(a2),a0
  1894.     move.w    accs_Position(a2),d0
  1895.     move.w    accs_Length(a2),d1
  1896.     cmp.w    d1,d0
  1897.     bge    StringAgain
  1898. KeyDel:
  1899.     cmp.w    d1,d0            ;move last part of string
  1900.     bge.s    .Found
  1901.     move.b    1(a0,d0.w),(a0,d0.w)
  1902.     addq.w    #1,d0
  1903.     bra.s    KeyDel
  1904. .Found    subq.w    #1,d1
  1905.     blt.w    StringLoop
  1906.     move.w    d1,accs_Length(a2)
  1907.     bra    StringLoop
  1908.  
  1909. KeyCRight:                ;--- Cursor Right
  1910.     move.w    accs_Position(a2),d0
  1911.     cmp.w    accs_Length(a2),d0
  1912.     bge.w    StringAgain
  1913.     addq.w    #1,accs_Position(a2)
  1914.     bsr    AdjustField
  1915.     lea    sCursorRight(pc),a0
  1916.     moveq    #-1,d0
  1917.     move.l    a0,a1
  1918.     move.l    a3,a0
  1919.     bsr    DisplayRaw
  1920.     bra    StringLoop
  1921.  
  1922. KeyCLeft:                ;--- Cursor Left
  1923.     move.w    accs_Position(a2),d0
  1924.     cmp.w    #0,d0
  1925.     ble.w    StringAgain
  1926.     subq.w    #1,accs_Position(a2)
  1927.     bsr    AdjustField
  1928.     lea    sCursorLeft(pc),a0
  1929.     moveq    #-1,d0
  1930.     move.l    a0,a1
  1931.     move.l    a3,a0
  1932.     bsr    DisplayRaw
  1933.     bra    StringLoop
  1934.  
  1935. KeySCRight:                ;--- <SHIFT> + Cursor Right
  1936.     move.w    accs_Length(a2),d0
  1937.     cmp.w    accs_Position(a2),d0
  1938.     beq.w    StringAgain
  1939.     move.w    d0,accs_Position(a2)
  1940.     bsr    AdjustField
  1941.     bra    StringLoop
  1942.  
  1943. KeySCLeft:                ;--- <SHIFT> + Cursor Left
  1944.     tst.w    accs_Position(a2)
  1945.     beq    StringAgain
  1946.     clr.w    accs_Position(a2)
  1947.     bsr    AdjustField
  1948.     bra    StringLoop
  1949.  
  1950. KeyRestore:                ;--- <AMIGA> + q
  1951.     move.l    accs_WorkBuffer(a2),d0    ;copy buffer to string
  1952.     beq    StringLoop
  1953.     move.l    d0,a0
  1954.     move.l    accs_InputBuffer(a2),a1
  1955.     move.w    accs_MaxLength(a2),d0
  1956.     subq.w    #1,d0
  1957. .CopyLoop
  1958.     move.b    (a0)+,(a1)+
  1959.     dbra    d0,.CopyLoop
  1960.  
  1961.     clr.w    accs_Position(a2)
  1962.     move.l    accs_InputBuffer(a2),a0    ;determine length
  1963.     move.w    accs_MaxLength(a2),d0
  1964.     subq.w    #1,d0
  1965.     moveq    #0,d1
  1966. .TLoop    tst.b    (a0)+
  1967.     beq.s    .TExit
  1968.     addq.w    #1,d1
  1969.     dbra    d0,.TLoop
  1970. .TExit    move.w    d1,accs_Length(a2)
  1971.     bsr    AdjustField
  1972.     bra    StringLoop
  1973.  
  1974. KeyClearLine:                ;--- <AMIGA> + x
  1975.     clr.w    accs_Position(a2)
  1976.     clr.w    accs_Length(a2)
  1977.     bsr    AdjustField
  1978.     bra    StringLoop
  1979.  
  1980. KeyClearEOL:                ;--- <AMIGA> + y
  1981.     move.w    accs_Position(a2),accs_Length(a2)
  1982.     bsr    AdjustField
  1983.     bra    StringLoop
  1984.  
  1985. KeyToggle:                ;--- <AMIGA> + a
  1986.     bchg    #ACCB_OVERWRITE,d6
  1987.     bra    StringLoop
  1988.  
  1989. ;------------------------------------------------------------------
  1990. AdjustField:
  1991.     move.l    d0,-(sp)
  1992.     move.w    accs_Position(a2),d0
  1993.     sub.w    accs_FieldLen(a2),d0
  1994.     bgt.s    .001
  1995.     clr.w    d0
  1996. .001    move.w    d0,accs_DispPos(a2)
  1997.     move.l    (sp)+,d0
  1998.     rts
  1999.  
  2000. ;------------------------------------------------------------------
  2001. CopyChar2Buffer:
  2002.     move.b    acc_Char(a2),d1
  2003.     beq.s    .Exit
  2004.     cmp.b    #CSI,d1
  2005.     beq.s    .Exit
  2006.     move.l    accs_InputBuffer(a2),a1
  2007.     move.w    accs_Position(a2),d0
  2008.  
  2009.     btst    #ACCB_OVERWRITE,d6
  2010.     bne.s    .OverWrite
  2011.  
  2012.     move.w    accs_Length(a2),d2    ;adjust length
  2013.     cmp.w    accs_MaxLength(a2),d2
  2014.     bge.s    .MLoop
  2015.     addq.w    #1,d2
  2016.     move.w    d2,accs_Length(a2)
  2017. .MLoop    cmp.w    d0,d2            ;move last part of string
  2018.     ble.s    .OverWrite
  2019.     subq.w    #1,d2
  2020.     move.b    (a1,d2.w),1(a1,d2.w)
  2021.     bra.s    .MLoop
  2022. .OverWrite
  2023.     move.b    d1,(a1,d0.w)        ;place new char in string
  2024.  
  2025.     cmp.w    accs_MaxLength(a2),d0
  2026.     bge.s    .End
  2027.     addq.w    #1,d0
  2028.     cmp.w    accs_Length(a2),d0
  2029.     ble.s    .End
  2030.     move.w    d0,accs_Length(a2)
  2031.  
  2032. .End    move.w    d0,accs_Position(a2)
  2033.     bsr    AdjustField
  2034. .Exit    rts
  2035.  
  2036. ;------------------------------------------------------------------
  2037. EchoBuffer:
  2038.     move.w    cnh_CursorStatus(a3),d3
  2039.     move.w    #CURSOROFF,d0        ;cursor off
  2040.     move.l    a3,a0
  2041.     bsr    Cursor
  2042.  
  2043.     move.w    acc_XStart(a2),d0    ;place cursor
  2044.     move.w    acc_YStart(a2),d1
  2045.     move.l    a3,a0
  2046.     bsr    GotoXY
  2047.  
  2048.     move.l    a2,-(sp)        ;display string
  2049.     move.l    accs_InputBuffer(a2),a0
  2050.     move.w    accs_Length(a2),d0
  2051.     clr.b    (a0,d0.w)
  2052.     adda.w    accs_DispPos(a2),a0
  2053.     move.l    a0,-(sp)
  2054.     move.l    sp,a2
  2055.     lea    vsJustBuffer(a4),a1
  2056.     move.l    a3,a0
  2057.     moveq    #-1,d0
  2058.     bsr    Display
  2059.     addq.l    #4,sp
  2060.     move.l    (sp)+,a2
  2061.  
  2062.     btst    #ACCB_JUSTIFIED,d6    ;Place cursor
  2063.     beq.s    .001
  2064.     move.w    accs_FieldLen(a2),d0    ;;
  2065.     add.w    accs_Position(a2),d0
  2066.     sub.w    accs_Length(a2),d0
  2067.     bra.s    .002
  2068. .001    move.w    accs_Position(a2),d0
  2069. .002    sub.w    accs_DispPos(a2),d0
  2070.     add.w    acc_XStart(a2),d0
  2071.     move.w    acc_YStart(a2),d1
  2072.     move.l    a3,a0
  2073.     bsr    GotoXY
  2074.  
  2075.     move.w    d3,d0            ;restore cursor status
  2076.     move.l    a3,a0
  2077.     bsr    Cursor
  2078.     rts
  2079.  
  2080. ;------------------------------------------------------------------
  2081. PrepareEcho:
  2082.     PUSH    a2/a3
  2083.     btst    #ACCB_JUSTIFIED,d6
  2084.     beq.s    .001
  2085.     lea    sJEcho(pc),a1
  2086.     bra.s    .002
  2087. .001    lea    sEcho(pc),a1
  2088. .002    move.w    accs_FieldLen(a2),d0
  2089.     move.w    d0,-(sp)    ;max
  2090.     move.w    d0,-(sp)    ;min
  2091.     move.l    sp,a2
  2092.     move.l    a3,a0
  2093.     lea    vsJustBuffer(a4),a3
  2094.     moveq    #32,d0        ;this should be enough
  2095.     bsr    DoFormat    ;format text to give the new format text
  2096.     addq.l    #4,sp
  2097.     PULL    a2/a3
  2098.     rts
  2099.  
  2100. ;------------------------------------------------------------------
  2101. ;    @Convert
  2102. ;------------------------------------------------------------------
  2103. ;
  2104. ; Convert a string to a value.
  2105. ;
  2106. ; Decimal, Hex and Binary supported.
  2107. ; Octal and Float not supported yet.
  2108. ;
  2109. ;------------------------------------------------------------------
  2110. ; IN    d0.l    = Flags
  2111. ;    d1.w    = MaxLen (or NULL-term)
  2112. ;    a1.l    = ^String
  2113. ;    a2.l    = ^Space for Result (Size: 32 bits)
  2114. ; OUT    d0.l    = ^Result (0 = Error)
  2115. ;------------------------------------------------------------------
  2116.  
  2117. Convert:
  2118.     PUSH    d2-d4/a2-a4
  2119.     subq.w    #1,d0
  2120.     beq.s    ConvertDecimal
  2121.     subq.w    #1,d0
  2122.     beq    ConvertHex
  2123.     subq.w    #1,d0
  2124.     beq    ConvertOctal
  2125.     subq.w    #1,d0
  2126.     beq    ConvertBinary
  2127. ConvertError:
  2128.     moveq    #0,d0
  2129. ConvertExit:
  2130.     PULL    d2-d4/a2-a4
  2131.     rts
  2132.  
  2133. ;------------------------------------------------------------------
  2134. ConvertDecimal:
  2135.     move.l    a1,a3
  2136. .Loop    tst.b    (a3)+
  2137.     beq.s    .ZeroFound
  2138.     dbra    d1,.Loop
  2139. .ZeroFound            ;a3 points behind number
  2140.     subq.l    #1,a3
  2141.     move.l    a3,d0
  2142.     sub.l    a1,d0        ;determine numbers of ciffers
  2143.     beq.s    ConvertError    ;skip if too small
  2144.     cmp.w    #10,d0
  2145.     bgt.s    ConvertError    ;skip if too large
  2146.     clr.l    (a2)
  2147.     lea    alDecimalArray(pc),a4
  2148.     subq.w    #1,d0
  2149. .DecLoop
  2150.     moveq    #0,d3
  2151.     move.l    (a4)+,d2
  2152.     move.b    -(a3),d3
  2153.     sub.b    #'0',d3
  2154.     blo.s    ConvertError
  2155.     cmp.b    #9,d3
  2156.     bhi.s    ConvertError
  2157.     move.l    d3,d4
  2158.     mulu    d2,d3
  2159.     swap    d2
  2160.     mulu    d2,d4
  2161.     swap    d4
  2162.     add.l    d4,d3
  2163.     add.l    d3,(a2)
  2164.     bcs    ConvertError
  2165.     dbra    d0,.DecLoop
  2166.     move.l    a2,d0
  2167.     bra.s    ConvertExit
  2168.  
  2169. ;------------------------------------------------------------------
  2170. ConvertHex:
  2171.     move.l    a1,a3
  2172. .Loop    tst.b    (a3)+
  2173.     beq.s    .ZeroFound
  2174.     dbra    d1,.Loop
  2175. .ZeroFound            ;a3 points behind number
  2176.     subq.l    #1,a3
  2177.     move.l    a3,d0
  2178.     sub.l    a1,d0        ;determine numbers of ciffers
  2179.     beq    ConvertError    ;skip if too small
  2180.     cmp.w    #8,d0
  2181.     bgt    ConvertError    ;skip if too large
  2182.     moveq    #0,d3
  2183.     moveq    #0,d1
  2184.     subq.w    #1,d0
  2185. .HexLoop
  2186.     move.b    (a1)+,d3
  2187.     sub.b    #'0',d3
  2188.     blt    ConvertError
  2189.     cmp.b    #9,d3
  2190.     ble.s    .HexNum
  2191.     bclr    #5,d3
  2192.     sub.b    #7,d3
  2193.     cmp.b    #$0A,d3
  2194.     blt    ConvertError
  2195.     cmp.b    #$0F,d3
  2196.     bgt    ConvertError
  2197. .HexNum    lsl.l    #4,d1
  2198.     or.w    d3,d1
  2199.     dbra    d0,.HexLoop
  2200.     move.l    d1,(a2)
  2201.     move.l    a2,d0
  2202.     bra    ConvertExit
  2203.  
  2204. ;------------------------------------------------------------------
  2205. ConvertOctal:
  2206.     RETURN    0
  2207.  
  2208. ;------------------------------------------------------------------
  2209. ConvertBinary:
  2210.     move.l    a1,a3
  2211. .Loop    tst.b    (a3)+
  2212.     beq.s    .ZeroFound
  2213.     dbra    d1,.Loop
  2214. .ZeroFound            ;a3 points behind number
  2215.     subq.l    #1,a3
  2216.     move.l    a3,d0
  2217.     sub.l    a1,d0        ;determine numbers of ciffers
  2218.     beq    ConvertError    ;skip if too small
  2219.     cmp.w    #32,d0
  2220.     bgt    ConvertError    ;skip if too large
  2221.     clr.l    (a2)
  2222.     moveq    #0,d1
  2223.     subq.w    #1,d0
  2224. .BinLoop
  2225.     move.b    (a1)+,d3
  2226.     sub.b    #'0',d3
  2227.     blt    ConvertError
  2228.     cmp.b    #1,d3
  2229.     bgt    ConvertError
  2230.     lsr.b    #1,d3
  2231.     roxl.l    #1,d1
  2232.     dbra    d0,.BinLoop
  2233.     move.l    d1,(a2)
  2234.     move.l    a2,d0
  2235.     bra    ConvertExit
  2236.  
  2237. ;------------------------------------------------------------------
  2238. ;    @SetMsgHandler
  2239. ;------------------------------------------------------------------
  2240. ;
  2241. ; Set Message Handler.
  2242. ;
  2243. ;------------------------------------------------------------------
  2244. ; IN    a0.l    = ConHandle
  2245. ;    a1.l    = ^NewMsgHandler
  2246. ; OUT    d0.l    = ^OldMsgHandler
  2247. ;------------------------------------------------------------------
  2248.  
  2249. SetMsgHandler:
  2250.     move.l    cnh_MsgHandler(a0),d0
  2251.     move.l    a1,cnh_MsgHandler(a0)
  2252.     rts
  2253.  
  2254. ;------------------------------------------------------------------
  2255. ;    @GetInfo
  2256. ;------------------------------------------------------------------
  2257. ;
  2258. ; Get some information about window.
  2259. ;
  2260. ;------------------------------------------------------------------
  2261. ; IN    a0.l    = ConHandle
  2262. ;    a1.l    = ^ConInfo
  2263. ; OUT    d0.l    = ^ConInfo
  2264. ;------------------------------------------------------------------
  2265.  
  2266. GetInfo:
  2267.     PUSH    d1/a2
  2268.     move.l    cnh_Unit(a0),a2
  2269.     move.w    cu_XCCP(a2),cin_XPos(a1)
  2270.     move.w    cu_YCCP(a2),cin_YPos(a1)
  2271.     move.w    cu_XMax(a2),cin_XSize(a1)
  2272.     move.w    cu_YMax(a2),cin_YSize(a1)
  2273.     moveq    #0,d0
  2274.     move.b    cu_AlgoStyle(a2),d1
  2275.     bne.s    .001
  2276.     bset    #SGFB_PLAIN,d0
  2277.     bra.s    .004
  2278. .001    btst    #FSB_BOLD,d1
  2279.     bne.s    .002
  2280.     bset    #SGFB_BOLD,d0
  2281. .002    btst    #FSB_ITALIC,d1
  2282.     bne.s    .003
  2283.     bset    #SGFB_ITALIC,d0
  2284. .003    btst    #FSB_UNDERLINED,d1
  2285.     bne.s    .004
  2286.     bset    #SGFB_UNDERLINED,d0
  2287. .004    move.w    d0,cin_Styles(a1)
  2288.     move.b    cu_FgPen(a2),d0
  2289.     add.w    #30,d0
  2290.     move.w    d0,cin_FgCol(a1)
  2291.     move.b    cu_BgPen(a2),d0
  2292.     add.w    #40,d0
  2293.     move.w    d0,cin_BgCol(a1)
  2294.     move.l    a1,d0
  2295.     PULL    d1/a2
  2296.     rts
  2297.  
  2298. ;------------------------------------------------------------------
  2299. ;    @SetGfx
  2300. ;------------------------------------------------------------------
  2301. ;
  2302. ; Set styles and colors for window.
  2303. ;
  2304. ;------------------------------------------------------------------
  2305. ; IN    a0.l    = ConHandle
  2306. ;    d0.w    = Styles
  2307. ;    d1.w    = Foreground Color
  2308. ;    d2.w    = Background Color
  2309. ; OUT    -
  2310. ;------------------------------------------------------------------
  2311.  
  2312. SetGfx:
  2313.     PUSH    a1/a2/a3
  2314.     move.l    sp,a3
  2315.     move.l    #"%dm"<<8,-(sp)    ;BgCol
  2316.     move.l    #"%-d;",-(sp)    ;FgCol
  2317.     btst    #SGFB_PLAIN,d0
  2318.     beq.s    .001
  2319.     move.l    #"%-d;",-(sp)
  2320. .001    btst    #SGFB_BOLD,d0
  2321.     beq.s    .002
  2322.     move.l    #"%-d;",-(sp)
  2323. .002    btst    #SGFB_ITALIC,d0
  2324.     beq.s    .003
  2325.     move.l    #"%-d;",-(sp)
  2326. .003    btst    #SGFB_UNDERLINED,d0
  2327.     beq.s    .004
  2328.     move.l    #"%-d;",-(sp)
  2329. .004    move.w    #CSI,-(sp)
  2330.     move.l    sp,a1
  2331.     addq.l    #1,a1
  2332.     move.w    d2,-(sp)    ;BgCol
  2333.     move.w    d1,-(sp)    ;FgCol
  2334.     btst    #SGFB_PLAIN,d0
  2335.     beq.s    .101
  2336.     move.w    #0,-(sp)
  2337. .101    btst    #SGFB_BOLD,d0
  2338.     beq.s    .102
  2339.     move.w    #1,-(sp)
  2340. .102    btst    #SGFB_ITALIC,d0
  2341.     beq.s    .103
  2342.     move.w    #3,-(sp)
  2343. .103    btst    #SGFB_UNDERLINED,d0
  2344.     beq.s    .104
  2345.     move.w    #4,-(sp)
  2346. .104    move.l    sp,a2
  2347.     moveq    #-1,d0
  2348.     bsr    Display
  2349.     move.l    a3,sp
  2350.     PULL    a1/a2/a3
  2351.     rts
  2352.  
  2353. ;------------------------------------------------------------------
  2354. ;    @GotoXY
  2355. ;------------------------------------------------------------------
  2356. ;
  2357. ; Place cursor at (X,Y).
  2358. ;
  2359. ;------------------------------------------------------------------
  2360. ; IN    a0.l    = ConHandle
  2361. ;    d0.w    = XPos
  2362. ;    d1.w    = YPos
  2363. ; OUT    -
  2364. ;------------------------------------------------------------------
  2365.  
  2366. GotoXY:
  2367.     PUSH    a1/a2
  2368.     lea    sGotoXY(pc),a1
  2369.     move.w    d0,-(sp)
  2370.     move.w    d1,-(sp)
  2371.     move.l    sp,a2
  2372.     moveq    #-1,d0
  2373.     bsr    Display
  2374.     addq.l    #4,sp
  2375.     PULL    a1/a2
  2376.     rts
  2377.  
  2378. ;------------------------------------------------------------------
  2379. ;    @Scroll
  2380. ;------------------------------------------------------------------
  2381. ;
  2382. ; Scroll text in window <Step> lines.
  2383. ;
  2384. ;------------------------------------------------------------------
  2385. ; IN    a0.l    = ConHandle
  2386. ;    d0.w    = Step
  2387. ; OUT    -
  2388. ;------------------------------------------------------------------
  2389.  
  2390. Scroll:
  2391.     PUSH    a1/a2
  2392.     tst.w    d0
  2393.     beq.s    .Exit
  2394.     bmi.s    .001
  2395.     lea    sScrollDn(pc),a1
  2396.     bra.s    .002
  2397. .001    lea    sScrollUp(pc),a1
  2398. .002    move.w    d0,-(sp)
  2399.     moveq    #-1,d0
  2400.     move.l    sp,a2
  2401.     bsr    Display
  2402.     addq.l    #2,sp
  2403. .Exit    PULL    a1/a2
  2404.     rts
  2405.  
  2406. ;------------------------------------------------------------------
  2407. ;    @Cursor
  2408. ;------------------------------------------------------------------
  2409. ;
  2410. ; Set Cursor mode.
  2411. ;
  2412. ; Currently only ON and OFF.
  2413. ;
  2414. ;------------------------------------------------------------------
  2415. ; IN    a0.l    = ConHandle
  2416. ;    d0.w    = Mode
  2417. ; OUT    -
  2418. ;------------------------------------------------------------------
  2419.  
  2420. Cursor:
  2421.     move.l    a1,-(sp)
  2422.     move.w    d0,cnh_CursorStatus(a0)
  2423.     beq.s    .001
  2424.     lea    sCursorOn(pc),a1
  2425.     bra.s    .002
  2426. .001    lea    sCursorOff(pc),a1
  2427. .002    moveq    #-1,d0
  2428.     bsr    DisplayRaw
  2429.     move.l    (sp)+,a1
  2430.     rts
  2431.  
  2432.  
  2433. ;==================================================================
  2434. ;==================================================================
  2435. ;===                                ===
  2436. ;===            DATA  AREA                ===
  2437. ;===                                ===
  2438. ;==================================================================
  2439. ;==================================================================
  2440.  
  2441. ;--- Variable -----------------------------------------------------
  2442.  
  2443. pSysBase:    dc.l    0
  2444. dWriteReplyPort:dcb.b    MP_SIZE,0
  2445.  
  2446. ;--- Text ---------------------------------------------------------
  2447.  
  2448. sLibName    dc.b    'con.library',0
  2449. sLibID        dc.b    'Console Library by BReese (31 oct 1991)',13,10,0
  2450. sIntName    dc.b    'intuition.library',0
  2451. sMathName    dc.b    'mathffp.library',0
  2452. sConDevName    dc.b    'console.device',0
  2453. sDosName    dc.b    'dos.library',0
  2454.  
  2455. sDosText
  2456.     dc.b    10,CSI,"1mCon.library",CSI,"0m is "
  2457.     dc.b    "a Copyright © 1991 by Bjørn Reese."
  2458.     dc.b    10,"------ You can't execute me, I'm a library ------"
  2459.     dc.b    10,10,0
  2460. sDosTextEnd
  2461.  
  2462. sDoStyle1    dc.b    27,'[0m',0
  2463. sDoStyle2    dc.b    27,'[1m',0
  2464. sDoStyle3    dc.b    27,'[3m',0
  2465. sDoStyle4    dc.b    27,'[4m',0
  2466. sDoFgCol    dc.b    27,'[30m',0
  2467. sDoBgCol    dc.b    27,'[40m',0
  2468.  
  2469. sEcho        dc.b    '%%-0%d.%ds',0
  2470. sJEcho        dc.b    '%%0%d.%ds',0
  2471. sGotoXY        dc.b    CSI,'%d;%dH',0
  2472. sCursorRight    dc.b    CSI,'C',0
  2473. sCursorLeft    dc.b    CSI,'D',0
  2474. sCursorOn    dc.b    CSI,' p',0
  2475. sCursorOff    dc.b    CSI,'0 p',0
  2476. sScrollUp    dc.b    CSI,'%dS',0
  2477. sScrollDn    dc.b    CSI,'%dT',0
  2478.  
  2479. sClear        dc.b    12,0        ;Unused
  2480. sInsCh        dc.b    CSI,'%d@',0    ;-
  2481. sDelCh        dc.b    CSI,'%dP',0    ;-
  2482. sInsLn        dc.b    CSI,'L',0    ;-
  2483. sDelLn        dc.b    CSI,'M',0    ;-
  2484.     EVEN
  2485.  
  2486. ;--- Table --------------------------------------------------------
  2487.  
  2488. alDecArray:
  2489.     dc.l    1000000000
  2490.     dc.l    100000000
  2491.     dc.l    10000000
  2492.     dc.l    1000000
  2493.     dc.l    100000
  2494.     dc.l    10000
  2495.     dc.l    1000
  2496.     dc.l    100
  2497.     dc.l    10
  2498.     dc.l    0
  2499.  
  2500. alDecimalArray:
  2501.     dc.l    1
  2502.     dc.l    10
  2503.     dc.l    100
  2504.     dc.l    1000
  2505.     dc.l    10000
  2506.     dc.l    100000
  2507.     dc.l    1000000
  2508.     dc.l    10000000
  2509.     dc.l    100000000
  2510.     dc.l    1000000000
  2511.  
  2512. awDefDefTable:
  2513.     dc.w    alDefAll-awDefDefTable
  2514.     dc.w    alDefEmpty-awDefDefTable
  2515.     dc.w    alDefAlfanum-awDefDefTable
  2516.     dc.w    alDefAlfa-awDefDefTable
  2517.     dc.w    alDefNumeric-awDefDefTable
  2518.     dc.w    alDefDecimal-awDefDefTable
  2519.     dc.w    alDefHex-awDefDefTable
  2520.     dc.w    alDefOctal-awDefDefTable
  2521.     dc.w    alDefBinary-awDefDefTable
  2522.     dc.w    alDefFloat-awDefDefTable
  2523.  
  2524. alDefAll:
  2525.     dc.l    $ffffffff,$ffffffff,$ffffffff,$ffffffff
  2526.     dc.l    $ffffffff,$ffffffff,$ffffffff,$ffffffff
  2527. alDefEmpty:
  2528.     dc.l    0,0,0,0,0,0,0,0
  2529. alDefAlfanum:
  2530.     dc.l    0
  2531.     dc.l    %11111111111111111111111111111111 ;<SPC> ->
  2532.     dc.l    %11111111111111111111111111111111 ;A ->
  2533.     dc.l    %11111111111111111111111111111110 ;a ->  minus <DEL>
  2534.     dc.l    0
  2535.     dc.l    %11111111111111111111111111111111 ;<S-SPC> ->
  2536.     dc.l    %11111111111111111111111111111111 ;À ->
  2537.     dc.l    %11111111111111111111111111111111 ;à ->
  2538. alDefAlfa:
  2539.     dc.l    0
  2540.     dc.l    %10000000000000000000000000000000 ;<SPC>
  2541.     dc.l    %01111111111111111111111111100000 ;ABCDEFGHIJKLMNOPQRSTUVWXYZ
  2542.     dc.l    %01111111111111111111111111100000 ;abcdefghijklmnopqrstuvwxyz
  2543.     dc.l    0
  2544.     dc.l    %10000000000000000000000000000000 ;<S-SPC>
  2545.     dc.l    %11111111111111111111111011111111 ;À ->  minus ×
  2546.     dc.l    %11111111111111111111111011111111 ;à ->  minus ÷
  2547. alDefNumeric:
  2548.     dc.l    0
  2549.     dc.l    %00000000000011101111111111000000    ;,-.0123456789
  2550.     dc.l    0,0,0,0,0,0
  2551. alDefDecimal:
  2552.     dc.l    0
  2553.     dc.l    %00000000000001001111111111000000    ;-0123456789
  2554.     dc.l    0,0,0,0,0,0
  2555. alDefHex:
  2556.     dc.l    0
  2557.     dc.l    %00000000000001001111111111000000    ;-0123456789
  2558.     dc.l    %01111110000000000000000000000000    ;ABCDEFG
  2559.     dc.l    %01111110000000000000000000000000    ;abcdefg
  2560.     dc.l    0,0,0,0
  2561. alDefOctal:
  2562.     dc.l    0
  2563.     dc.l    %00000000000001001111111100000000    ;-01234567
  2564.     dc.l    0,0,0,0,0,0
  2565. alDefBinary:
  2566.     dc.l    0
  2567.     dc.l    %00000000000001001100000000000000    ;-01
  2568.     dc.l    0,0,0,0,0,0
  2569. alDefFloat:
  2570.     dc.l    0
  2571.     dc.l    %00000000000111101111111111000000    ;+,-.0123456789
  2572.     dc.l    %00000100000000000000000000000000    ;E
  2573.     dc.l    %00000100000000000000000000000010    ;e^
  2574.     dc.l    0,0,0,0
  2575.  
  2576.  
  2577. ;--- END OF LIBRARY -----------------------------------------------
  2578.     CNOP    0,4
  2579. EndLib:
  2580.  
  2581.  
  2582.     IFNE    DEBUG
  2583.  
  2584. ;==================================================================
  2585. ;==================================================================
  2586. ;===                                ===
  2587. ;===            DEBUG CODE AREA                ===
  2588. ;===                                ===
  2589. ;==================================================================
  2590. ;==================================================================
  2591.  
  2592. ;--- Comment ------------------------------------------------------
  2593. ;
  2594. ; To execute a function you may use CALL or JSR.
  2595. ; - CALL is is the normal and correct way to access the function.
  2596. ; - JSR is used to single-step into the actual library code.
  2597. ;
  2598. ;------------------------------------------------------------------
  2599.  
  2600. ;--- System -------------------------------------------------------
  2601.  
  2602.     BASEREG    DebugDataArea,a5
  2603.  
  2604. ;==================================================================
  2605. ;===
  2606. ;===    @DebugCode
  2607. ;===
  2608. ;==================================================================
  2609.  
  2610.     SECTION    ConDebug,CODE
  2611.  
  2612. DebugCode:
  2613.     lea    DebugDataArea(pc),a5    ;Global Data Pointer
  2614.  
  2615. ;--- Prepare Con Library
  2616.  
  2617.     move.l    (_SysBase).w,a6
  2618.     lea    LibFuncTable,a0
  2619.     lea    LibDataTable,a1
  2620.     lea    LibInit,a2
  2621.     move.l    #con_SIZEOF,d0
  2622.     moveq    #0,d1
  2623.     CALL    MakeLibrary
  2624.     move.l    d0,pLibrary(a5)
  2625.     beq    .Error
  2626.     move.l    d0,a1
  2627.     CALL    AddLibrary
  2628.  
  2629. ;--- Open Con Library
  2630.  
  2631.     moveq    #0,d0
  2632.     lea    sConName(a5),a1
  2633.     CALL    OpenLibrary
  2634.     move.l    d0,pConBase(a5)
  2635.  
  2636. ;--- Open ConWindow
  2637.  
  2638.     move.l    pConBase(a5),a6
  2639.     lea    dMyWindow(a5),a0
  2640.     move.w    #CURSORON,d0
  2641.     CALL    OpenCon
  2642.     move.l    d0,pConHandle(a5)
  2643.  
  2644. ;--- Test various function
  2645.  
  2646.     move.l    pConBase(a5),a6        ;Global for tests
  2647.     bsr    TestConvert
  2648.     bsr    TestDisplay
  2649.     bsr    TestDefineChars
  2650.     bsr    TestAcceptString
  2651.     bsr    TestAccept
  2652.  
  2653. ;--- Clean up everything
  2654.  
  2655.     move.l    pConBase(a5),a6
  2656.     move.l    pConHandle(a5),a0
  2657.     CALL    CloseCon
  2658.  
  2659.     move.l    (_SysBase).w,a6
  2660.     move.l    pConBase(a5),a1
  2661.     CALL    CloseLibrary
  2662.  
  2663.     move.l    pLibrary(a5),a1
  2664.     CALL    RemLibrary
  2665. .Error    moveq    #0,d0
  2666.     rts
  2667.  
  2668.  
  2669. ;------------------------------------------------------------------
  2670. ;    @TestConvert
  2671. ;------------------------------------------------------------------
  2672. ;
  2673. ; Convert a number (base determined by CNV_xxx in D0)
  2674. ; and print it.
  2675. ;
  2676. ;------------------------------------------------------------------
  2677.  
  2678. TestConvert:
  2679.     move.l    #CNV_HEX,d0
  2680.     moveq    #-1,d1
  2681.     lea    sNumber(pc),a1
  2682.     lea    lNumber(pc),a2
  2683.     jsr    Convert
  2684.     tst.l    d0
  2685.     beq.s    .NoCnvt
  2686.  
  2687.     move.l    d0,a2
  2688.     move.l    pConHandle(pc),a0
  2689.     lea    sNumberText(pc),a1
  2690.     moveq    #-1,d0
  2691.     CALL    Display
  2692. .NoCnvt    rts
  2693.  
  2694. ;------------------------------------------------------------------
  2695. ;    @TestDefineChars
  2696. ;------------------------------------------------------------------
  2697. ;
  2698. ; DefineChars must be called before using Accept/AcceptString to
  2699. ; be sure that the correct chars are defined.
  2700. ;
  2701. ; DEFMODE_GET and DEFMODE_NEW are used to create a table from
  2702. ; scratch, whereas DEFMODE_ADD and DEFMODE_SUB are used to change
  2703. ; a table.
  2704. ;
  2705. ;------------------------------------------------------------------
  2706.  
  2707. TestDefineChars:
  2708.  
  2709. ;--- Define ValidChars in Input structure
  2710.  
  2711.     lea    dInput+acc_ValidTable(pc),a1
  2712.     move.l    #DEFMODE_GET+DEFALFANUM,d0
  2713.     jsr    DefineChars
  2714.  
  2715. ;--- Define ExitChars in Input structure
  2716.  
  2717.     lea    dInput+acc_ExitTable(pc),a1
  2718.     move.l    #DEFMODE_NEW,d0
  2719.     lea    aExitInput(pc),a2
  2720.     jsr    DefineChars
  2721.  
  2722. ;--- Define ValidChars in Keypress structure
  2723.  
  2724.     lea    dKeypress+acc_ValidTable(pc),a1
  2725.     move.l    #DEFMODE_NEW,d0
  2726.     lea    sValidKeypress(pc),a2
  2727.     jsr    DefineChars
  2728.  
  2729. ;--- Define ExitChars in Keypress structure
  2730.  
  2731.     lea    dKeypress+acc_ExitTable(pc),a1
  2732.     move.l    #DEFMODE_NEW,d0
  2733.     lea    aExitKeypress(pc),a2
  2734.     jsr    DefineChars
  2735.     rts
  2736.  
  2737. ;------------------------------------------------------------------
  2738. ;    @TestDisplay
  2739. ;------------------------------------------------------------------
  2740. ;
  2741. ; Nice and simple.
  2742. ;
  2743. ;------------------------------------------------------------------
  2744.  
  2745. TestDisplay:
  2746.     moveq    #-1,d0
  2747.     move.l    pConHandle(pc),a0
  2748.     lea    sGoodDay(pc),a1
  2749.     lea    wGoodArg(pc),a2
  2750.     jsr    Display
  2751.     rts
  2752.  
  2753. ;------------------------------------------------------------------
  2754. ;    @TestAcceptString
  2755. ;------------------------------------------------------------------
  2756. ;
  2757. ; Get an input string and display it.
  2758. ;
  2759. ;------------------------------------------------------------------
  2760.  
  2761. TestAcceptString:
  2762.  
  2763. ;--- Get an input string
  2764.  
  2765.     move.l    pConHandle(pc),a0
  2766.     move.l    #ACCF_ERASE!ACCF_FULLSTOP,d0
  2767.     lea    dInput(pc),a1
  2768.     jsr    AcceptString
  2769.  
  2770. ;--- Display the string found in accs_InputBuffer
  2771.  
  2772.     lea    lInputArg(pc),a2
  2773.     lea    dInput(pc),a1
  2774.     move.l    accs_InputBuffer(a1),(a2)
  2775.     moveq    #-1,d0
  2776.     move.l    pConHandle(pc),a0
  2777.     lea    sInputText(pc),a1
  2778.     CALL    Display
  2779.     rts
  2780.  
  2781. ;------------------------------------------------------------------
  2782. ;    @TestAccept
  2783. ;------------------------------------------------------------------
  2784. ;
  2785. ; Display a message at a certain location and wait until a valid
  2786. ; char was pressed.
  2787. ;
  2788. ; \{ was used in the text, but GotoXY() could have been used as well
  2789. ;
  2790. ;------------------------------------------------------------------
  2791.  
  2792. TestAccept:
  2793.  
  2794. ;--- Display message
  2795.  
  2796. .Again    moveq    #-1,d0
  2797.     move.l    pConHandle(pc),a0
  2798.     lea    sContinue(pc),a1
  2799.     CALL    Display
  2800.  
  2801. ;--- Get key
  2802.  
  2803.     move.l    pConHandle(pc),a0
  2804.     move.l    #ACCF_WAIT!ACCF_ECHO!ACCF_ERASE,d0
  2805.     lea    dKeypress(pc),a1
  2806.     jsr    Accept
  2807.  
  2808. ;--- Repeat until a valid key was found
  2809.  
  2810.     cmp.w    #2,d0
  2811.     beq.s    .Again
  2812.     tst.w    d0
  2813.     bmi.s    .Again
  2814.     rts
  2815.  
  2816.  
  2817. ;==================================================================
  2818. ;==================================================================
  2819. ;===                                ===
  2820. ;===            DEBUG DATA AREA                ===
  2821. ;===                                ===
  2822. ;==================================================================
  2823. ;==================================================================
  2824.  
  2825. DebugDataArea:
  2826.  
  2827. ;--- Variable -----------------------------------------------------
  2828.  
  2829. pConHandle    dc.l    0
  2830. pConBase    dc.l    0
  2831. pLibrary    dc.l    0
  2832.  
  2833. lNumber        dc.l    0
  2834. wGoodArg    dc.w    5432
  2835. lInputArg    dc.l    0
  2836.  
  2837.  
  2838. ;--- Text ---------------------------------------------------------
  2839.  
  2840. sConName    dc.b    'con.library',0
  2841. sWindowTitle    dc.b    ' ==== ',0
  2842.  
  2843. sNumber        dc.b    'ffffffff',0
  2844. sNumberText    dc.b    'Number was: %lu',10,0
  2845.  
  2846. aExitInput    dc.b    27,13,AKEY_HELP,0
  2847. sValidKeypress    dc.b    AKEY_F1,13,'Yy',0
  2848. aExitKeypress    dc.b    27,'Nn',0
  2849.  
  2850. sGoodDay    dc.b    'This is a test',10,10
  2851.         dc.b    '\Z3\B Here''s a\@ number: %d',10,0
  2852. sInputText    dc.b    10,10,10,'Input was: "%s"',10,0
  2853. sContinue    dc.b    '\{12;30HContinue\{14;30H(Y/N):',0
  2854.     EVEN
  2855.  
  2856. ;--- Table --------------------------------------------------------
  2857.  
  2858. ;--- AcceptStructure for a simple keypress
  2859.  
  2860. dKeypress:
  2861.     dc.w    -1,-1            ;XStart,YStart
  2862.     dc.w    -1,-1,-1        ;Styles,FgCol,BgCol
  2863.     dc.l    CLOSEWINDOW        ;ExitFlags
  2864.     dcb.l    7,0            ;Message stuff
  2865.     dc.b    0,0            ;Char,Pad001
  2866.     dcb.b    CHARDEFSIZE,-1        ;ValidTable
  2867.     dcb.b    CHARDEFSIZE,-1        ;ExitTable
  2868.     dcb.l    4,0            ;Reserved
  2869.  
  2870. ;--- AcceptStructure for a input line
  2871.  
  2872. dInput:
  2873.     dc.w    30,5            ;XStart,YStart
  2874.     dc.w    SGFF_BOLD,-1,-1        ;Styles,FgCol,BgCol
  2875.     dc.l    CLOSEWINDOW        ;ExitFlags
  2876.     dcb.l    7,0            ;Message stuff
  2877.     dc.b    0,0            ;Char,Pad001
  2878.     dcb.b    CHARDEFSIZE,-1        ;ValidTable
  2879.     dcb.b    CHARDEFSIZE,-1        ;ExitTable
  2880.     dcb.l    4,0            ;Reserved
  2881.     dc.l    sInputBuffer        ;InputBuffer
  2882.     dc.l    sWorkBuffer        ;WorkBuffer
  2883.     dc.w    40,30            ;MaxLength,FieldLen
  2884.     dc.w    0            ;Length
  2885.     dc.w    0,0            ;Position,DispPos
  2886.     dcb.l    2,0            ;Reserved
  2887.  
  2888. ;--- Intuition NewWindow Structure
  2889.  
  2890. MyIDCMP    SET CLOSEWINDOW
  2891. MyFlags    SET WINDOWSIZING!WINDOWDRAG!WINDOWDEPTH!WINDOWCLOSE
  2892. MyFlags    SET MyFlags!SMART_REFRESH!ACTIVATE!NOCAREREFRESH
  2893.  
  2894. dMyWindow:
  2895.     dc.w    0,11        ;LeftEdge, TopEdge
  2896.     dc.w    640,245        ;Width, Height
  2897.     dc.b    0,1        ;DetailPen, BlockPen
  2898.     dc.l    MyIDCMP        ;IDCMPFlags
  2899.     dc.l    MyFlags        ;Flags
  2900.     dc.l    0,0        ;FirstGadget, CheckMark
  2901.     dc.l    sWindowTitle    ;Title
  2902.     dc.l    0        ;Screen
  2903.     dc.l    0        ;BitMap
  2904.     dc.w    640,30        ;MinWidth, MinHeight
  2905.     dc.w    -1,-1        ;MaxWidth, MaxHeight
  2906.     dc.w    WBENCHSCREEN    ;Type
  2907.  
  2908. ;--- Buffer -------------------------------------------------------
  2909.  
  2910. sInputBuffer:
  2911.     dc.b    'Original buffer',0
  2912.     dcb.b    80-[*-sInputBuffer],0
  2913. sWorkBuffer:
  2914.     dcb.b    80,0
  2915.  
  2916.     ENDC
  2917.